How to add data to DynamoDB table using AWS Lambda(serverless) function?

AWS Lambda is a compute service that lets you run code without provisioning or managing servers.

Amazon DynamoDB is a fast and flexible nonrelational database service for all applications that need consistent, single-digit millisecond latency at any scale.

Let us see how we can execute our code in AWS Lambda so that it saves the data in the DynamoDB Table.

Step 1) Sign in to your AWS Management Console and Go to Services ->Compute -> Lambda


Step 2) Create a Lambda function and enter details as below.

In the role, create a custom role with DynamoDB Full Access Policy in AWS IAM.



Step 3) Go to DynamoDB and Create a table.


Click on Create table:


Enter the table name and primary key as shown below:


Click on create.

Your table has been created.


Add other required columns like author name and book name.


Step 4) Go back to your Lambda function. Add the following code:


Step 5) Add Table name in Lambda Environment Variables.


Step 6) Configure Test Event to execute function with example data.


Add test data and click on create:


Step 7) Now Save and Run the function: Click on “Test”

Finally your lambda function is executed successfully,


Go to your DynamoDB table and check the data:


Here it is! You are done!

Any Queries??

Post your comments below.














One thought on “How to add data to DynamoDB table using AWS Lambda(serverless) function?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s