DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 967,611 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for Do your first AWS Lambda Serverless Node.js API
Luiz Calaça
Luiz Calaça

Posted on • Updated on

Do your first AWS Lambda Serverless Node.js API

Hi, Devs!

First we need to install


Let's create a folder:

$ mkdir node-aws
Enter fullscreen mode Exit fullscreen mode

Go into that folder and run:

$ cd node-aws
$ serverless
Enter fullscreen mode Exit fullscreen mode

Now is going to appear some questions after you choosed the AWS - Node.js - HTTP API:

? What do you want to call this project? **aws-node-api**

βœ” Project successfully created in aws-node-api folder

? What org do you want to add this service to? **[Skip]**

? Do you want to deploy now? **No**
Enter fullscreen mode Exit fullscreen mode

Open your folder that was created and now we can look at:

Handler AWS Serverless

When we use serverless deploy our application is going to start the process on AWS, and we go there and see the queue on CloudFormation. You can use search tool and find all the services below.

search tool on AWS

CloudFormation
It organize a queue of services processing to deploy our service. when we run serverless deploy there is a folder .serverless with Cloudformation informations do deploy. AWS CloudFormation has a template for this Serverless application. Look at below the events created by that service.
CloudFormation Event

AWS IAM
User management. You can verify yours users.

AWS Lambda
It was created a function called aws-node-api-dev-hello because into our handler.js there's a function called hello and it is configured on serverless.yml. Look at below:
serverless.yml and handler.js

S3
Data storage on AWS, and it is created a bucket after our deploy with serverless framework.
S3

API Gateway
The API Gateway service helps us to create an excellent pattern to access our API. It show us all the routes of the system and here we can add Authorization, CORS configurations and create new routes.

API Gateway

When we access the Lambda service we can see the API Gateway in a pipe clicking on Functions -> choose the function that we created -> Function overview:

AWS Lambda - API Gateway

CloudWatch
Monitoring the API with a couple metrics

AWS CloudWatch

At the final we have the URL to access our API: https://h5c2vw466m.execute-api.us-east-1.amazonaws.com/

You can find the URL looking for API Gateway service in search tool and click on the project name that we created.

Contacts
Email: luizcalaca@gmail.com
Instagram: https://www.instagram.com/luizcalaca
Linkedin: https://www.linkedin.com/in/luizcalaca/
Twitter: https://twitter.com/luizcalaca

Top comments (0)

Take a look at this:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›