Last Updated on
Serverless Computing allows you to concentrate on your application code instead of managing servers or installing any software. You can build a Serverless Website by using AWS Lambda, a serverless compute service and it’s simply great.
I’ll take you through the entire process of configuration and uploading your application code to AWS. So, without further ado, lets get started.
Build Your First Serverless Website in 7 Easy Steps
There are a few simple steps you will have to take in order to get up and running, so let’s walk the walk together and start with taking a look at the road ahead.
Here is an example of Serverless Application Architecture
- Aws Free Tier Account
- Install Nodejs v8+ and nmp
I’m using the serverless framework CLI to create and deploy apps.
Please make sure that
npm is installed correctly and if you encounter any errors, check nmpjs documentation or execute the following commands to solve common
nmp related problems quickly;
npm cache clean --force
npm i npm@latest -g
We have to install Serverless globally, so fire up a terminal window and run:
npm install -g serverless
Note: You may need to run the command as sudo.
Next up we’ll login into our newly installed serverless platform, type the following command:
You’ll have a new browser window open up asking you to log in (you can use GitHub or Google account for authentication).
You can follow on screen instructions to create a username and app name, once completed you will see default information page, similar to this:
After that’s done, you can create a new folder for the project and we need to create a simple serverless boilerplate.
sls create --template hello-world
Once done, you’ll end up with something similar to this:
Next we need to get our AWS credentials configured. Let’s jump in and see it in action.
Configure AWS Credentials
The process is simple but requires multiple steps. Navigate to your AWS Console and click on Services dropdown in the top left corner.
You’ll see a ton of services show up, Go ahead and select IAM under “Security Identity and Complaince” or write IAM in the search box and use the following instructions to create a user and grant necessary privileges..
Set User Details
Create a new username and only select Programmatic access to continue.
Go ahead and click on Attach existing policies directly and only select AdministratorAccess under the Policy section to continue.
Review the details to continue to user setup.
Proceeding to the next step you will see the user was created. Now, and only now will you have access to the users Access Key ID and Secret Access Key.
Save IAM keys in the Serverless configuration
Fire up terminal and type the following command in one line:
Now your Serverless installation is configured with AWS account.
Before we start installing dependencies for our serverless website, you will need to create a package.json file by executing the following command in terminal.
You’ll be asked to provide names and descriptions and a lot of other information. Since this is a test just hit “Enter” and leave all the fields empty.
We are going to install express web framework to get things going faster, install some dependancies and edit some files. Type the following in your terminal:
Install Express Framework
npm install express --save
Install the Body-Parser Middleware
npm install --save body-parser
Install View Engine for Express
sudo npm install --save hbs
Install Serverless-HTTP to Connect API to AWS
npm install --save serverless-http
Create a Website
Create a Service
In less than minute it will return an endpoint that we can open up in a browser.
You can now go ahead and boldly Say “Hello World”
You’ve successfully deployed your first Serverless Website.
I’ve also got this data-centric newsletter that you might be into. I send a tiny email once every fortnight (if that) with some useful and cool stuff I’ve found/made.Don’t worry, I hate spam as much as you.