Open In App
Related Articles

AWS DynamoDB – Insert Data Using AWS Lambda

Improve Article
Save Article
Like Article

In this article, we will look into the process of inserting data into a DynamoDB table using AWS Lambda. Amazon DynamoDB is a completely owned NoSQL proprietary provider that helps key-value and textual statistics systems and is supplied via way of means of as a part of Amazon Web Services. AWS Lambda is an event-driven, serverless computing platform supplied via way means of Amazon as part of Amazon Web Services. It is a computing service that runs code without us worrying about servers. Users can simply use the AWS Lambda function so as to process the records in an Amazon DynamoDB stream. With the help of DynamoDB Streams, Users can easily trigger the Lambda function so as to perform additional work every time a DynamoDB table will be updated. Some permissions are also needed  to manage the resources related to your DynamoDB stream like dynamodb:GetRecords, dynamodb:GetShardIterator, dynamodb:ListStreams and dynamodb:DescribeStream. User have to Add this into their function’s execution role. Users can create an event for source mapping to tell that their  Lambda sends the records from your stream to a Lambda function. By default, the Lambda can invokes your function as soon as the records are available. The Lambda polls also shards in your DynamoDB stream service for the records having base rate of 4 times per second.


Follow the below steps to insert data into the DynamoDB table using AWS lambda:

Step 1: Login into AWS console.

Step 2: Search for dynamodb.


Step 3: Select Dynamodb and press on create table


Step 4: Now give the table name and keys accordingly to your requirement 


Now table will be created.

Step 5: Now we need to create Identity and Access Management(IAM) role for that go and search for IAM role.

Step 6: Click on role in access management and click on create role.



Step 7: Here we need to select AWS service and lambda.


Step 8: Here we need to add permission, as we are using dynamo db we need to add AmazonDynamoDBFullAccess Permissions policies


Step 9: Now give the role name and select create role


Step 10: Press on create function.


Step 11: Give name and Runtime.


Step 12: Change the Execution role to Use an existing role and select your role.


Step 13: Now go to the code section and add the below code.


#importing packages
import json
import boto3
#function definition
def lambda_handler(event,context):
    dynamodb = boto3.resource('dynamodb')
    #table name
    table = dynamodb.Table('sample')
    #inserting values into table
    response = table.put_item(
            'sample': 'bhagi',
    return response



Lost in the complex landscape of DevOps? It's time to find your way! Enroll in our DevOps Engineering Planning to Production Live Course and set out on an exhilarating expedition to conquer DevOps methodologies with precision and timeliness.
What We Offer:
  • Comprehensive DevOps Curriculum
  • Expert Guidance for Streamlined Learning
  • Hands-on Experience with Real-world Scenarios
  • Proven Track Record with 100,000+ Successful DevOps Enthusiasts

Last Updated : 28 Mar, 2023
Like Article
Save Article
Similar Reads
Complete Tutorials