Performing CRUD Operations on DynamoDB using Lambda Function
Hello connections , I want to share my knowledge regarding AWS in my posts. In this article i want to explain you all about "Implementation of CRUD operations on Dynamo DB and AWS lambda" .
CRUD OPERATIONS means Creating , Retrieving , Updating and Deleting.
I want to explain step by step process to order to make you understand clearly!!
First Lets create a DynamoDB Table with name as "studenttable" and also partition key as"sid" and sort key as "sname". In any DynamoDB table , partition key is also considered as primary key which is unique. DynamoDB is a NOSQL Database where we store Unstructured data.
Now, Lets create a Lambda function
click on create function
we will use a predefined template hello-world-function with python 3.7 --> configure
Let's create a IAM role to give permissions for Lambda to deal with DynamoDB
choose Lambda as use case --> next
choose AmazonDynamoDBFullAccess as permission policies--> next
give a role name for the role which we created
our role is created successfully !!! Hurrah !! ...Lets go back to our Lambda function .
give function name , choose "use an existing role" --> choose the role that we created just now.
leave the remaining settings as default and click on create function.
write code for inserting the record into dynamodb table.
Recommended by LinkedIn
create a new demo event and give the values which we want to be inserted into the table.
click on test button to see the sucess msg.
Now, lets check our dynamoDB table , to check whether the record insewrted or not. We got it !! We can see the record which we given in demoevent.
simillarly , Lets insert another record in our table.
Lets write a code to deelete the record and we should provide the partition key and sort key of the record which we want to dlt in the test tab . Then click on red Test button to see our code execution.
we can see that , our code compiled successfully!!
we can see that record got dlted .
Lets write code to display the items in the table , we can see the records which are in the table.
code for updating a field in the table
in the demoevent provide parition and sort key of the record in which you want to update a filed.
Now, execute the code.
We can see the updated field in the dynamoDB!!! Congo , we have completed the CRUD operations implementations in DynamoDB.