DEV Community

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

Posted on • Edited 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
```



Go into that folder and run:



```
$ cd node-aws
$ serverless
```



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**
```



---

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

![Handler AWS Serverless](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g89r9djgmvat3gq6bf25.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5v1fno9fweoh0fc4l0im.png)

**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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/guywiwkuxx30dg8kgg1o.png)

**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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x774c4pxfdxmlhegx82v.png)

**S3**
Data storage on AWS, and it is created a bucket after our deploy with serverless framework.
![S3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/24evbgeqq03vbirnsrmy.png)

**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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gt0egwhu122g8yact34d.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xvtzt4wja9r6hcz353iq.png)

**CloudWatch**
Monitoring the API with a couple metrics

![AWS CloudWatch](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7m33sdqt3iofq9xjn3df.png)

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
Enter fullscreen mode Exit fullscreen mode

Top comments (0)