top of page

Serverless Implementation - AWS Lambda, API Gateway and DynamoDB

  • dotsincloud
  • Mar 2
  • 2 min read

 

 

ree

 


Courtesy:draw.io

 

Abstract:

 

Amazon API gateway created, maintains and secures API at a scale. Essentially it is collection of API’s that user leverages to make calls using methods such as GET, POST,etc. In this simple use case, we create a serverless API using API gateway, Lambda, and DynamoDB.

 

Setup:

 

Create Lambda IAM Role

 

We create an execution role that gives the function permission to access AWS resource.  

 

IAM

 

Create Lambda Function

 

To create a Lambda function,

1.        Search for Lambda in AWS console.

2.        Click create function.

a.        Select "Author from scratch". Use name LambdaFunctionOverHttps.

b.        Select Python 3.9 as Runtime.

c.        Under Permissions, select "Use an existing role”.

d.        From the drop down Select lambda-apigateway-role that we created.

3.        Replace the boilerplate coding with the following code snippet and click "Save"


ree

 

Create a test event

 

ree


Execute test.

 

ree


ree

 

At this point we are redy to create a DynamoDB table and API using our Lambda as backend.

 

Create DynamoDB Table

 

ree

Table is created.

 

ree

 

ree

 Create API

 

To create API ,

1.        Go to API gateway in AWS console.

2.        Click Create API.

3.        Scroll down and select “Buil” for REST API.

 

ree

4.        Giving API name as DynamoDBOperations.


ree

5.        Click Create API.

 

ree

 

Each API is collection of resources and methods that are integrated with backend HTTP endpoints, Lambda functions, or other AWS services. Typically, API resources are organized in a resource tree according to the application logic. At this time, you only have the root resource, but let's add a resource next.

 

Click Action and create resource.

 

ree

Inputting DynamoDBManager in the resource name. The resource path get activated and create resource.

 

ree

 

Create method

Create a POST Method for our API. With the "/dynamodbmanager" resource selected, Click "Actions" again and click "Create Method".

 

ree

 

ree

 

 Our API-Lambda integration is done!

 

Deploy API

Click "Actions", select "Deploy API"

 

ree

 

Running the solution.

 

To execute our API from local machine, we are going to use Postman and Curl command. 

 

{

    "operation": "create",

    "tableName": "lambda-apigateway",

    "payload": {

        "Item": {

            "id": "1234ABCD",

            "number": 5

        }

    }

}

 

Listed the inserted item – to validate the item has been inserted in the DynamoDB, go to Dynamo console, select "lambda-apigateway" table, select "Items" tab, and the newly inserted item should be displayed.


 

ree

 

List the inserted item – Postman


ree

We have successfully created a serverless API using API Gateway, Lambda, and DynamoDB!


 
 
 

Recent Posts

See All
GIT - Conflict Resolution

Situation: I have forked a repository. When trying to raise a PR form forked repository to original repository in Bitbucket I am getting...

 
 
 

Comments


Post: Blog2_Post
  • LinkedIn

©2021 by Dots in Cloud. Proudly created with Wix.com

bottom of page