Step-by-Step Guide to Using Lambda Proxy Integrations in Amazon API Gateway

Hello, I am a full stack developer since 2010 focused for a long moment more on backend stuffs. I embraced cloud development since 2019.
Search for a command to run...

Hello, I am a full stack developer since 2010 focused for a long moment more on backend stuffs. I embraced cloud development since 2019.
No comments yet. Be the first to comment.
In this mini-series, we will quickly and effortlessly build a simple CRUD nodeJs serverless backend using Amazon web services Lambda, API gateway, DynamoDb, Cognito, etc.
In this article, we'll build a simple CRUD JavaScript-based backend with AWS. We'll use Lambda and DynamoDB to show how you can quickly create a secure and robust app backend. Prerequisites To follow this tutorial, you need an AWS account. Thankfully...
Security in internet-facing or local applications is one of the most challenging parts of the software development life cycle. This post will provide a quick step-by-step guide to implementing access management for the previous REST API using Amazon ...

In this article, we'll build a simple CRUD JavaScript-based backend with AWS. We'll use Lambda and DynamoDB to show how you can quickly create a secure and robust app backend. Prerequisites To follow this tutorial, you need an AWS account. Thankfully...

There are many articles on how to build a real-world Spring Boot CRUD REST API or Application with MySQL as a Relational Database. In this post, we are not only going to show how to create a Spring Boot CRUD operations API, but we will also dive deep...

Before entering the AWS Cloud world, as a Java developer, it was often difficult for me to get Java-based applications online for my clients. Fortunately, I found out later that AWS provides many proven, fully managed services for deploying Java-bas...

In this post, we will create a REST API endpoint with GET and POST methods for the previous backend using Amazon API Gateway's HTTP API.
All you need is just an AWS account: no worries, if you are new to AWS, AWS offers you a 12-month free tier account where you can play with lots of services as a developer (isn't it cool? 😜)
Amazon API Gateway is an AWS service that helps you create and secure REST and HTTP APIs at any scale.
The following steps will show you how to create an HTTP API and set up a POST method for an API resource.
Let's use the AWS console to create the API Gateway.




Provide the Stage name*: dev* (1) and then click Next (2) in the Configure stages step.

The last step is to review what we provided in the previous steps and click Create (1).





Let's update this lambda function to handle the GET and POST requests we created above.
As of the time we are writing this article, the version of the event payload format that API Gateway sends to Lambda is 2.0.
We will use the routeKey attribute value from the event payload to get the request route path. This will help direct traffic to the corresponding Lambda CRUD methods. Additionally, we will use the queryStringParameters attribute value to get request parameters.
The index.mjs file's handler function becomes this:

An environment variable called TABLE is created to handle the DynamoDB table's name. We retrieve its value into the TABLE_NAME variable in line 4: const TABLE_NAME = process.env.TABLE;. More information about Lambda environment variables can be found here.
In line 5, we get the routeKey value, which is the API request's path from the API Gateway. This value will be used in line 14 to call the suitable action implemented in the Lambda function.
This pattern is called Lambda monolith: using a single backend Lambda function to dispatch incoming traffic to multiple implemented actions. It's used for simplicity and is more suitable for small applications or monolith applications migrated to AWS Lambda. Take a look at this documentation for the recommendation.

Open Postman, choose the POST method, paste the URL, and append /api/items.
Select the Body tab, and past the payload data (3) then click Send (4) to get the result (5) if everything is ok.

In this post, we provided a step-by-step guide to creating an API Gateway HTTP API with Lambda proxy integrations, highlighting the Lambda monolith pattern. You can find the source code for the Lambda function here.
Thanks for reading 😊. Your suggestions and comments are welcome. Akpé kaka 🙏!