This article will help you to understand how to insert records into AWS dynamo DB with the help of the lambda function.
What is Dynamo DB?
Amazon DynamoDB is a fully managed NoSQL database service that allows to the creation of database tables that can store and retrieve any amount of data. It automatically manages the data traffic of tables over multiple servers and maintains performance. It also relieves the customers from the burden of operating and scaling a distributed database. Hence, hardware provisioning, setup, configuration, replication, software patching, cluster scaling, etc. is managed by Amazon.
Step1:= First of all we will create a table in Dynamo DB with a Partition key it is part of the table’s primary key. It is a hash value that is used to retrieve items from your table and allocate data across hosts for scalability and availability.
What is IAM user and role?
IAM roles. An IAM role is very similar to a user, in that it is an identity with permission policies that determine what the identity can and cannot do in AWS. However, a role does not have any credentials (password or access keys) associated with it.
Step2 := Create an IAM role for and attach two permission policies highlighted in the screenshot.
Plan. Expand. Optimize. A Cloud Migration Workbook.
Strategize the next steps of your organization's application modernization journey leveraging our experts' pragmatic approach.
What is Lambda function in AWS?
AWS Lambda is an event-driven, serverless computing platform provided by Amazon as a part of Amazon Web Services. Therefore, you don’t need to worry about which AWS resources to launch, or how will you manage them. Instead, you need to put the code on Lambda, and it runs.
In AWS Lambda the code is executed based on the response of events in AWS services such as add/delete files in S3 bucket, HTTP request from Amazon API gateway, etc. However, Amazon Lambda can only be used to execute background tasks.
Step3= Create a lambda function and choose the language to use to write your function as Python 3.9 and select Use an existing role (IAM) that you have created before.
Step4: = Write a python code in the lambda function to insert the records, I have attached the snapshot of the code for your reference and hit the deploy button.
Step5:= click on test and create a Test event and write your record in the form of keys and values (JSON format) and hit the test button.
Step6= After hitting the Test button, you will be able to see that record in the Dynamo DB table that means record inserted successfully.
Happy Reading and Learning.