Posted on

Integrating AWS API Gateway, Lambda and DynamoDB

On the whole AWS API Gateway is a beneficial package for the developer. These dedicated servers are explicitly set to handle the API calls for an application. Install the one specific to your Browser. It also has a useful testing platform which can be used to test the calls. It also provides caching and monitoring.

In my next blog I have talked about securing your API’s in API gateway, passing Query string & headers, transforming response type and returning the custom error code.The hands on is included. The increase in the number of API calls, increases the load of the API server which may require auto-scaling, which is cost-consuming.

1

The latest approach of the best architects is to utilize a new AWS service that explicitly replaces the need for a dedicated API Server. Finally a REST Client will be used to call the API.

Step 1: Create a DynamoDB table:
3
Create a DynamoDB table named Employee with the attributes of primary key as emp_id. Use code from the following location, https://s3-ap-southeast-1.amazonaws.com/cloudthatcode/addEmployee.zip. Use Lambda as the integration type and select the Lambda function you created earlier.

Test the API with the following values from the console.
{

“emp_id” : “2”

“emp_Name” : “Snow”

“emp_Salary” : “200000”

}

{

“emp_id” : “2”

“emp_Name” : “Snow”

“emp_Salary” : “200000”

}

You should see the entries in the DynamoDB table.

For creating an API we need to create Resource, create POST method under the resource and utilize the Lambda function as integration type and the Deployment of API is up for launch.

For Detailed Instructions..

Step 4: Call the API using REST Client

Test the API setup. The next part of the blog is a detailed tutorial on how to use AWS API Gateway along with AWS Lambda & DynamoDB.

People who are familiar with DynamoDB, API Gateway and Lambda can proceed with the high-level instructions. There are extensions for Mozilla firefox and Chrome which can be used which can be use to make REST calls. The bottleneck of this setup is that the API server has to be maintained to handle all the API calls. AWS API Gateway provides the ability to act as an interface between application and database which uses AWS Lambda function as the backend.

To get the essence of AWS API Gateway, we need to get hands-on with it. Invoke the API URL with the following values

{

“emp_id” : “3”

“emp_Name” : “Jack”

“emp_Salary” : “200000”

}

{

“emp_id” : “3”

“emp_Name” : “Jack”

“emp_Salary” : “200000”

}

Check the DynamoDB table again for the entries.

The response from the DynamoDB is processed by the Lambda function and routed via the API Gateway.

For Detailed Instructions..

With minimal effort a REST API has been created which accepts data, which in turn gets processed by Lambda function and finally stored in a DynamoDB table. Accept the rest of attributes as default and review the table details.

For Detailed Instructions..
Step 2: Create a Lambda Function:

Create a node.js Lambda function called addEmployee. Next a Lambda function which inserts the data into DynamoDB table. The API gateway provides nifty features where we can create different stages for development. Replace IAM access and secret keys of a user with access to write into the DynamoDB table.

For Detailed Instructions..

Step 3: Create an API in API Gateway :

Next create an API called Employee_API, a resource called employee and create a POST Method. If you have any queries on API gateway or you have trouble getting it setup, feel free to drop a question into the comment section below or you can also ask the questions to https://forum.cloudthat.com

Thank you. In the current world of API, every mobile application and website have to communicate using dedicated API servers. Also for people who are new to these services, there are detailed instructions which can be followed for step-by-step guidance.

The first step will be to create a DynamoDB table which stores the data. This API is ready for use and can be used in any application.

The API gateway frees the developer from maintaining infrastructure for APIs. API servers act as an intermediary between the application and the database. An API Gateway is setup to trigger the Lambda function. For this Install a REST client.

Leave a Reply