Configure serverless cli to setup and deploy node express API on AWS Lambda



Serverless CLI makes easy to create, deploy and monitor the application on the AWS Lambda. Can install serverless using npm in the local machine.

I will e creating a Node Express API endpoint using serverless and deploy it to AWS Lambda.

To configure serverless in the local machine globally 

npm install serverless -g


Once the serverless cli installed in local system, we can check if it is installed correctly by responding the version details.

$ serverless -v
Framework Core: 3.21.0
Plugin: 6.2.2
SDK: 4.3.2


Next we can create a project using serverless in the local machine, which later then can deploy to AWS lambda using serverless command.

$ serverless

The above command gives the below options to choose the the type of application that you want to create. Select the appropriate option ex:

Creating a new serverless project

Creating a new serverless project

  AWS - Node.js - Starter
? What do you want to make? AWS - Node.js - Express API


Before doing further process, make sure you have an account in aws and active user with administrator permission.

To configure serverless in local machine with AWS , it require to set it with AWS user Key and Secret.

It will ask for the configuration in the next step once you started creating project using serverless command as above.

Refer Serverless Framework - AWS Credentials  for setup.


Also in later stage we can setup Key and Secret using 


$ serverless config credentials --overwrite --provider aws --key <Key> --secret <Secret>


Next , a copy of project template would be created, navigate to that directory and run 


$ serverless deploy

Deploying aws-node-express-api-project to stage dev (us-east-1)

✔ Service deployed to stack aws-node-express-api-project-dev (3012s)

endpoint: ANY - https://rfzhaa489e.execute-api.us-east-1.amazonaws.com
functions:
  api: aws-node-express-api-project-dev-api (868 kB)


Above command will deploy the project which configured using serverless cli in local to AWS Lambda, and the endpoint would be exposed to run the API .


Now my all routes are available at

 endpoint: ANY - https://rfzhaa489e.execute-api.us-east-1.amazonaws.com


Refer the Git hub for sample code reference.

avinashkumar-github/serverless-cli-aws-node-express-api: A basic node express api application setup using serverless cli to deploy it on AWS lambda