DEV Community

Cover image for Quick-starting an AWS Serverless Framework Project
victoroliveirab
victoroliveirab

Posted on

Quick-starting an AWS Serverless Framework Project

Step -1: Download Node.JS to your computer

Step 0: Download Serverless Framework CLI via npm:

npm i -g serverless
Enter fullscreen mode Exit fullscreen mode

Step 1: Setup AWS Credentials to your Serverless CLI:

sls config credentials --provider aws --key YOURKEY --secret YOURSECRETKEY
Enter fullscreen mode Exit fullscreen mode

In order to access your key and your secret key, you must log in to AWS console and navigate to IAM Management and click on Users. Create a user, allow programmatic access, attach an existing policy called AdministratorAccess to it, and then click on your recently created User. Navigate to Security Credentials, click on Create access key, and take note of the two values, especially the secret key as you won't be able to visualize it again.

Step 2: Create a project setting a template and a path. A list of templates (along with many of the information I am providing here) can be found here:

sls create --template aws-nodejs-typescript --path project-name
Enter fullscreen mode Exit fullscreen mode

This will generate a NodeJS project with a package.json file, handler.ts, which contains a sample lambda function, and serverless.yml, which contains configuration to the AWS services we might want to set.

Step 3: Navigate to your newly created project and install the libraries listed on package.json:

cd project-name && npm i
Enter fullscreen mode Exit fullscreen mode

Step 4: Install some developing tools to improve your experience. I recommend the following:

npm i -D prettier serverless-offline serverless-dotenv-plugin
Enter fullscreen mode Exit fullscreen mode

Prettier is a very well known opinative code formatted; Serverless Offline is a package that emulates AWS API Gateway and Lambda on your local machine, which facilitates a lot the development cycle, testing, and debugging; Serverless DotENV allows us to store environment variables in a .env file and access its values in our code and serverless.yml file.

Step 4.1: In case you opted to install at least one of the serverless plugins I mentioned before, add them to your serverless.yml plugins list:

plugins:
  - serverless-webpack # This one should be already there for the template I used here
  - serverless-offline
  - serverless-dotenv-plugin
Enter fullscreen mode Exit fullscreen mode

Step 5: Make sure everything is working correctly by launching serverless offline in your localhost:

sls offline
Enter fullscreen mode Exit fullscreen mode

And, in another shell session:

curl http://localhost:3000/dev/hello
Enter fullscreen mode Exit fullscreen mode

If this command prints a JSON response to your console, you're good to start developing 😄

Top comments (0)