Serverless framework setup for AWS using node js and npm

vaibhav sharma
4 min readMay 24, 2021

--

In this guide, we will go through the following:

  • Setting up of AWS Environment
  • Setting up of AWS CLI on windows
  • Setting up of Node Js and VSCode
  • Setting up of Serverless framework

We will be using Windows to carry out our operation.

Setting up AWS Environment on your system

Here we will set up an AWS environment in our local computer and create a new user to access AWS resources. To get started, you’ll need access to an AWS account. However, if you do not have one, Sign up for a free AWS account using this link. AWS provide you with a free tier of 12 months. You can get an understanding of AWS resources and their billing patterns from here.

So if you have an account ready. It is time to create a user. To create a new user we need to:

  • Login to your AWS account and search for IAM service on the service search filter.
  • Go to the Users page and click on Add User.
  • Now give a user name. let us name it as serverless tutorials and provide programmatic access to the user this will only create a set of API credentials i.e. an access key and a secret key and will not assign a password to the user. And click Next.
  • Now we need to set up permissions for this user. Click on Attach existing policies directly. And provide Administrator Access to the user. This is going to provide this user full access to your AWS account. And click Next.
  • Then on the next page it will ask you to add tags. skip that part and click Next. review the user and click Next. on the next page save your Access Key Id and Secret Access Key. Go to environment variables and set up Environment variables for ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS _DEFAULT_REGION. And click Close

Installing AWS CLI on your system

  • Install AWS CLI on your windows system from here. After installation go to the command prompt. to review your installation type aws help
  • now type aws sts get-caller-identity to get user information

Setup NodeJS

  • We will be using NodeJS and VS Code IDE and Postman tool to check APIs in our further tutorials. You can use any other IDE of your choice.
  • To install NodeJs got o nodeJs website and download/install LTS version for windows(x64). Review your installation by checking the node version by typing node --version in CMD prompt

Installing and configuring AWS Serverless framework

  • Serverless is provided as npm package. To install serverless open CMD prompt and type npm install -g serverless
  • To review your installation serverless -v to check the node version

Creating Your First Serverless Application with the Serverless Framework

  • Create a new project directory and open it in vs code.
  • Now hit Ctrl+` to open the terminal.
  • To create your first serverless template and a hello world application type serverless create -t aws-nodejs -p hello-world where hello-world is the name of the application.
  • This will set up a basic serverless project template for you. in the project template, you can find a serverless.yml file that contains the basic orchestration of projects like permissions, project information, lambda function information and events. There will be another file handler.js which is your main function or code that serves as a lambda function.

Hurray! You have set up the AWS and created your first serverless application. In the next tutorial, we will be creating a serverless application using AWS Lambda and API Gateway

--

--

vaibhav sharma

Full Stack IoT developer working on effective Wireless Sensor Network