{"id":103399,"date":"2020-03-30T19:00:02","date_gmt":"2020-03-30T16:00:02","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=103399"},"modified":"2020-03-30T17:56:24","modified_gmt":"2020-03-30T14:56:24","slug":"aws-lambda-to-save-data-in-dynamodb","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2020\/03\/aws-lambda-to-save-data-in-dynamodb.html","title":{"rendered":"AWS Lambda to save data in DynamoDB"},"content":{"rendered":"<p>In this tutorial, we will see how using AWS Lambda we can save data in Dynamo DB.<\/p>\n<p>Here are the steps which are required :<\/p>\n<p>&#8211;<b>Create a table in the Dynamo DB with the name Employee<\/b><br \/><b>&#8211; Create a AWS Lambda function which can save firstName and surName of an employee using a Employee POJO in the Dynamo DB<\/b><br \/><b>&#8211; Create a Policy which will give Read\/Write access to only Employee table of DynamoD<\/b>B<br \/><b>&#8211; Attach Policy to a Role<\/b><br \/><b>&#8211; Upload the code of AWS lambda function in the form of jar in the AWS lambda console<\/b><br \/><b>&#8211; Attach role created in step 4 to the AWS Lambda<\/b><br \/><b>&#8211; Run Test event to invoke AWS Lambda to save Employee data in Dynamo DB<\/b><\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"320\" height=\"180\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/LambdaDynamo.jpg\" alt=\"\" class=\"wp-image-103414\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/LambdaDynamo.jpg 320w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/LambdaDynamo-300x169.jpg 300w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">1. Create a table in the Dynamo DB with the name Employee<\/h2>\n<p><b>1.1 <\/b>To create a table in Dynamo DB, login to AWS console and in the services search for Dynamo DB or you can find DynamoDB service under Database.Click on Dynamo DB and you will see following screen.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"640\" height=\"316\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Screenshot-2020-03-23-at-20.37.30.png\" alt=\"\" class=\"wp-image-103415\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Screenshot-2020-03-23-at-20.37.30.png 640w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Screenshot-2020-03-23-at-20.37.30-300x148.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n<\/div>\n<p><b>1.2&nbsp;<\/b>To create an Employee table, click on the &#8220;Create table&#8221; button and you will see following screen. Enter table name as &#8220;Employee&#8221; and partition key as &#8220;emp_id&#8221; and click on &#8220;Create&#8221; button.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"640\" height=\"315\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Screenshot-2020-03-23-at-20.45.09.png\" alt=\"\" class=\"wp-image-103416\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Screenshot-2020-03-23-at-20.45.09.png 640w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Screenshot-2020-03-23-at-20.45.09-300x148.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n<\/div>\n<p>It will create Employee table for you as can be seen in below screenshot.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"640\" height=\"309\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Screenshot-2020-03-23-at-21.32.23.png\" alt=\"\" class=\"wp-image-103417\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Screenshot-2020-03-23-at-21.32.23.png 640w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Screenshot-2020-03-23-at-21.32.23-300x145.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n<\/div>\n<p>Just click on Items tab and you can see table with empId colum has been created.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"640\" height=\"315\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Screenshot-2020-03-23-at-21.33.48.png\" alt=\"\" class=\"wp-image-103418\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Screenshot-2020-03-23-at-21.33.48.png 640w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Screenshot-2020-03-23-at-21.33.48-300x148.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">2. Create a AWS Lambda function which can save firstName and surName of an Employee using an Employee POJO in the Dynamo DB<\/h2>\n<p><b>Dependencies in Pom.xml :<\/b><\/p>\n<pre class=\"brush:xml\">\n&lt;dependency&gt;\n    &lt;groupId&gt;com.amazonaws&lt;\/groupId&gt;\n    &lt;artifactId&gt;aws-lambda-java-core&lt;\/artifactId&gt;\n    &lt;version&gt;1.1.0&lt;\/version&gt;\n&lt;\/dependency&gt;\n&lt;dependency&gt;\n    &lt;groupId&gt;com.amazonaws&lt;\/groupId&gt;\n    &lt;artifactId&gt;aws-java-sdk-dynamodb&lt;\/artifactId&gt;\n    &lt;version&gt;1.11.0&lt;\/version&gt;\n&lt;\/dependency&gt;\n<\/pre>\n<p><b>Java Code :<\/b><\/p>\n<pre class=\"brush:java\">\npackage com.blogspot.javasolutionsguide.handler;\n\nimport com.amazonaws.regions.Region;\nimport com.amazonaws.regions.Regions;\nimport com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;\nimport com.amazonaws.services.dynamodbv2.document.DynamoDB;\nimport com.amazonaws.services.dynamodbv2.document.Item;\nimport com.amazonaws.services.dynamodbv2.document.PutItemOutcome;\nimport com.amazonaws.services.dynamodbv2.document.Table;\nimport com.amazonaws.services.dynamodbv2.document.spec.PutItemSpec;\nimport com.amazonaws.services.lambda.runtime.Context;\nimport com.amazonaws.services.lambda.runtime.RequestHandler;\nimport com.blogspot.javasolutionsguide.request.Employee;\nimport com.blogspot.javasolutionsguide.response.Response;\n\npublic class SaveEmployeeHandler implements RequestHandler<Employee, Response>{\n \n private DynamoDB dynamoDb;\n private String DYNAMO_DB_TABLE_NAME = \"Employee\";\n private Regions REGION = Regions.US_EAST_1;\n\n\n @Override\n public Response handleRequest(Employee personRequest, Context context) {\n  \n     this.initDynamoDbClient();\n     persistData(personRequest);\n     Response personResponse = new Response();\n     personResponse.setMessage(\"Message Saved Successfully\");\n  return personResponse;\n }\n \n private void initDynamoDbClient() {\n  AmazonDynamoDBClient client = new AmazonDynamoDBClient();\n  client.setRegion(Region.getRegion(REGION));\n  this.dynamoDb = new DynamoDB(client);\n }\n \n private PutItemOutcome persistData(Employee employee) {\n  Table table = dynamoDb.getTable(DYNAMO_DB_TABLE_NAME);\n  PutItemOutcome outcome = table.putItem(new PutItemSpec().withItem(\n    new Item().withNumber(\"empId\", employee.getEmpId())\n               .withString(\"firstName\", employee.getFirstName())\n               .withString(\"lastName\", employee.getLastName())));\n  return outcome;\n }\n}\n<\/pre>\n<p>3. Create a Policy which will give Read\/Write access to only Employee table of DynamoDB and attach with a Role<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>We need to provide access to AWS Lambda function to Read\/Write to Dynamo DB table.For that,we will create first a Polciy and then attach that policy to a Role.<\/p>\n<p>To create a new policy, go to Services and then IAM.<\/p>\n<p>Click on the Policies under Access Management and you will see following screen.<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"640\" height=\"297\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/policies.jpg\" alt=\"\" class=\"wp-image-103419\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/policies.jpg 640w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/policies-300x139.jpg 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n<p>Click on Create Policy and you will see following screen :<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"640\" height=\"301\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/CreatePoliy1.jpg\" alt=\"\" class=\"wp-image-103421\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/CreatePoliy1.jpg 640w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/CreatePoliy1-300x141.jpg 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n<\/div>\n<p>Click on &#8220;Choose a Service&#8221; and type DynamoDB in search box.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"640\" height=\"297\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/ChooseAService.jpg\" alt=\"\" class=\"wp-image-103422\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/ChooseAService.jpg 640w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/ChooseAService-300x139.jpg 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n<\/div>\n<p>Select Dynamo DB and then in Access Level section select GetItem and PutItem.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"640\" height=\"296\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/GetPut.jpg\" alt=\"\" class=\"wp-image-103423\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/GetPut.jpg 640w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/GetPut-300x139.jpg 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n<\/div>\n<p>Select Resources.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"640\" height=\"296\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Resources.jpg\" alt=\"\" class=\"wp-image-103424\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Resources.jpg 640w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Resources-300x139.jpg 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n<\/div>\n<p>Click on Add ARN.Fill Region where your Dynamo Db table is and enter name of your table and click Add.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"640\" height=\"297\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/AddArn.jpg\" alt=\"\" class=\"wp-image-103425\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/AddArn.jpg 640w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/AddArn-300x139.jpg 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n<\/div>\n<p>Click on Review Policy and enter name which you want to give to your policy and enter some description about this policy and then&nbsp; Click on Create Policy.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"640\" height=\"297\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/RevieePoliy.jpg\" alt=\"\" class=\"wp-image-103426\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/RevieePoliy.jpg 640w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/RevieePoliy-300x139.jpg 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">4. Create a Role and attach policy to the Role<\/h2>\n<p>Go to IAM service -&gt; Role, Click on Create Role button and you will see following screen. &nbsp;<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"640\" height=\"286\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/NextPermissions.jpg\" alt=\"\" class=\"wp-image-103427\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/NextPermissions.jpg 640w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/NextPermissions-300x134.jpg 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n<\/div>\n<p>Select AWS Service as Trusted Entity. This is the entity to which you want to assign the role, as we want to assign this role to Lambda function, which is AWS service only, we have chosen AWS service. Also in &#8220;Choose a use case&#8221;, select Lambda and then click on Next Permissions. You will see following screen. \u00a0 \u00a0\u00a0<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"640\" height=\"298\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/CreatePolicy.jpg\" alt=\"\" class=\"wp-image-103428\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/CreatePolicy.jpg 640w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/CreatePolicy-300x140.jpg 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n<\/div>\n<p>Now in the Filter policies, type the policy name that you just created in step 2(DynamoDBEmployeeTblAccess)<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"640\" height=\"298\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/SearchPolicy.jpg\" alt=\"\" class=\"wp-image-103429\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/SearchPolicy.jpg 640w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/SearchPolicy-300x140.jpg 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n<\/div>\n<p>Click on Next:Tags button and then Next:Review button on the next screen.On the next screen, give name &#8220;DynamoDBEmployeeTblAccess&#8221; in Role Name. Add Role description.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"640\" height=\"298\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/CreateRole1.jpg\" alt=\"\" class=\"wp-image-103430\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/CreateRole1.jpg 640w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/CreateRole1-300x140.jpg 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n<\/div>\n<p>Click on &#8220;Create Role&#8221; button and you will Success message as below:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"640\" height=\"297\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/RoleCreated.jpg\" alt=\"\" class=\"wp-image-103431\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/RoleCreated.jpg 640w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/RoleCreated-300x139.jpg 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">5. Upload the code of AWS lambda function in the form of jar in the AWS lambda console<\/h2>\n<p>All code for this tutorial has been put in my Git repository. Link is given at the end of this tutorial.<\/p>\n<p>So you can import that code in your workspace and then maven build it which will create jar for you and then following my previous tutorial&nbsp;<br \/><a href=\"https:\/\/javasolutionsguide.blogspot.com\/2020\/03\/how-to-create-aws-lambda-function-with.html\" target=\"_blank\" rel=\"noopener noreferrer\">How to create Aws Lambda function with Java<\/a>, you can upload jar easily to AWS lambda console.<\/p>\n<h2 class=\"wp-block-heading\" id=\"docs-internal-guid-8fec4180-7fff-2a1a-3378-68f08d31a371\">6. Attach role created in step 4 to the AWS Lambda<\/h2>\n<p>In the Permissions section of your Lambda, select &#8220;Attach an existing Role&#8221; and select role created in step 4 from drop down and then click on save.<\/p>\n<h2 class=\"wp-block-heading\">7. Run Test event to invoke AWS Lambda to save Person data in Dynamo DB<\/h2>\n<p>Once you have successfullly uploaded the jar,go to Select a Test event&#8221; drop down and then click on &#8220;Configure test events&#8221;.<\/p>\n<p>You will see screen with following data.Enter Event name as &#8220;HelloWorldEvents&#8221; and replace following data<\/p>\n<pre class=\"brush:bash\">\n{<br \/>\n  \"key1\": \"value1\",<br \/>\n  \"key2\": \"value2\",<br \/>\n \"key3\": \"value3\"<\/p>\n<p>}<\/p>\n<p>with below Json :<br \/>\n{<br \/>\n  \"empId\": 1,<br \/>\n  \"firstName\": \"Gaurav\",<br \/>\n  \"lastName\": \" Bhardwaj\"<\/p>\n<p>}<br \/>\n\/pre><\/p>\n<p>Click on \"save\" button and then on \"Test\" button.<\/p>\n<p>You should be able to see following screen.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"640\" height=\"322\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Screenshot-2020-03-23-at-21.51.27.png\" alt=\"\" class=\"wp-image-103433\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Screenshot-2020-03-23-at-21.51.27.png 640w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Screenshot-2020-03-23-at-21.51.27-300x151.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n<\/div>\n<p>Now go to your Dynamo Db service and open Employee table and click on Start search button and you should be able to see following record :<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"640\" height=\"313\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Screenshot-2020-03-23-at-21.53.15.png\" alt=\"\" class=\"wp-image-103434\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Screenshot-2020-03-23-at-21.53.15.png 640w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/03\/Screenshot-2020-03-23-at-21.53.15-300x147.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n<\/div>\n<p>You can find all code for this tutorial in <a href=\"https:\/\/github.com\/gauravbhrdwj\/javaSolutionsGuide\/tree\/master\/aws-lambda-dynamo-saveemployee\" target=\"_blank\" rel=\"noopener noreferrer\">GitHub<\/a>.<\/p>\n<h2 class=\"wp-block-heading\">Summary and Few important points:<\/h2>\n<p>So ,in this tutorial, we saw that<\/p>\n<p>- How a Lambda function can be used to save data in Dynamo DB.<\/p>\n<p>- We created only empId attribute and Dynamo Db automatically created rest of the attributes for us when we saved Employee object, as it has firstName and surName attributes and name of the POJO matches with the name of the table.Alternatively, we are free to create table with all three attributes as well from DynamoDB console.<\/p>\n<p>- If we will try to save same object(with same Id) again, it is just going to override the existing object, so there will not be any exception.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>\n<p>Published on Java Code Geeks with permission by Gaurav Bhardwaj, partner at our <a href=\"\/\/www.javacodegeeks.com\/join-us\/jcg\/\" target=\"_blank\" rel=\"noopener noreferrer\">JCG program<\/a>. See the original article here: <a href=\"http:\/\/javasolutionsguide.blogspot.com\/2020\/03\/aws-lambda-to-save-data-in-dynamo-db.html\" target=\"_blank\" rel=\"noopener noreferrer\">AWS Lambda to save data in DynamoDB<\/a><\/p>\n<p>Opinions expressed by Java Code Geeks contributors are their own.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will see how using AWS Lambda we can save data in Dynamo DB. Here are the steps which are required : &#8211;Create a table in the Dynamo DB with the name Employee&#8211; Create a AWS Lambda function which can save firstName and surName of an employee using a Employee POJO in &hellip;<\/p>\n","protected":false},"author":955,"featured_media":112,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[758,1365],"class_list":["post-103399","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-aws","tag-dynamodb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>AWS Lambda to save data in DynamoDB - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn about DynamoDB? Check our article explaining how to use AWS Lambda so we can save data in Dynamo DB with examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2020\/03\/aws-lambda-to-save-data-in-dynamodb.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"AWS Lambda to save data in DynamoDB - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn about DynamoDB? Check our article explaining how to use AWS Lambda so we can save data in Dynamo DB with examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2020\/03\/aws-lambda-to-save-data-in-dynamodb.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-30T16:00:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Gaurav Bhardwaj\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Gaurav Bhardwaj\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/03\\\/aws-lambda-to-save-data-in-dynamodb.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/03\\\/aws-lambda-to-save-data-in-dynamodb.html\"},\"author\":{\"name\":\"Gaurav Bhardwaj\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/58bd3e1f6edc1bed6a6374fe9a34ca37\"},\"headline\":\"AWS Lambda to save data in DynamoDB\",\"datePublished\":\"2020-03-30T16:00:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/03\\\/aws-lambda-to-save-data-in-dynamodb.html\"},\"wordCount\":958,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/03\\\/aws-lambda-to-save-data-in-dynamodb.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"keywords\":[\"AWS\",\"DynamoDB\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/03\\\/aws-lambda-to-save-data-in-dynamodb.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/03\\\/aws-lambda-to-save-data-in-dynamodb.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/03\\\/aws-lambda-to-save-data-in-dynamodb.html\",\"name\":\"AWS Lambda to save data in DynamoDB - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/03\\\/aws-lambda-to-save-data-in-dynamodb.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/03\\\/aws-lambda-to-save-data-in-dynamodb.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"datePublished\":\"2020-03-30T16:00:02+00:00\",\"description\":\"Interested to learn about DynamoDB? Check our article explaining how to use AWS Lambda so we can save data in Dynamo DB with examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/03\\\/aws-lambda-to-save-data-in-dynamodb.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/03\\\/aws-lambda-to-save-data-in-dynamodb.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/03\\\/aws-lambda-to-save-data-in-dynamodb.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"java-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/03\\\/aws-lambda-to-save-data-in-dynamodb.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"AWS Lambda to save data in DynamoDB\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/58bd3e1f6edc1bed6a6374fe9a34ca37\",\"name\":\"Gaurav Bhardwaj\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/657921afcac1f1ddf98dfb349121a07b4dcc1d42d5bd277150cf3ed8156de723?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/657921afcac1f1ddf98dfb349121a07b4dcc1d42d5bd277150cf3ed8156de723?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/657921afcac1f1ddf98dfb349121a07b4dcc1d42d5bd277150cf3ed8156de723?s=96&d=mm&r=g\",\"caption\":\"Gaurav Bhardwaj\"},\"description\":\"Gaurav has done Masters in Computer Applications(MCA) and is working in Software development field for more than 10 years in Java\\\/J2EE technologies. He is currently working with one of top MNC. He has worked on various frameworks like Struts, Spring, Spring Boot, Angular JS, JSF, Velocity, iBatis, MyBatis, Hibernate, JUnit, Mockito, Dozzer. He likes to explore new technologies and share his thoughts by writing a technical blog. He is the founder of JavaSolutionsGuide.blogspot.com.\",\"sameAs\":[\"http:\\\/\\\/www.javasolutionsguide.blogspot.nl\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/gaurav-bhardwaj\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"AWS Lambda to save data in DynamoDB - Java Code Geeks","description":"Interested to learn about DynamoDB? Check our article explaining how to use AWS Lambda so we can save data in Dynamo DB with examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2020\/03\/aws-lambda-to-save-data-in-dynamodb.html","og_locale":"en_US","og_type":"article","og_title":"AWS Lambda to save data in DynamoDB - Java Code Geeks","og_description":"Interested to learn about DynamoDB? Check our article explaining how to use AWS Lambda so we can save data in Dynamo DB with examples.","og_url":"https:\/\/www.javacodegeeks.com\/2020\/03\/aws-lambda-to-save-data-in-dynamodb.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2020-03-30T16:00:02+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","type":"image\/jpeg"}],"author":"Gaurav Bhardwaj","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Gaurav Bhardwaj","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2020\/03\/aws-lambda-to-save-data-in-dynamodb.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/03\/aws-lambda-to-save-data-in-dynamodb.html"},"author":{"name":"Gaurav Bhardwaj","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/58bd3e1f6edc1bed6a6374fe9a34ca37"},"headline":"AWS Lambda to save data in DynamoDB","datePublished":"2020-03-30T16:00:02+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/03\/aws-lambda-to-save-data-in-dynamodb.html"},"wordCount":958,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/03\/aws-lambda-to-save-data-in-dynamodb.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","keywords":["AWS","DynamoDB"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2020\/03\/aws-lambda-to-save-data-in-dynamodb.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2020\/03\/aws-lambda-to-save-data-in-dynamodb.html","url":"https:\/\/www.javacodegeeks.com\/2020\/03\/aws-lambda-to-save-data-in-dynamodb.html","name":"AWS Lambda to save data in DynamoDB - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/03\/aws-lambda-to-save-data-in-dynamodb.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/03\/aws-lambda-to-save-data-in-dynamodb.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","datePublished":"2020-03-30T16:00:02+00:00","description":"Interested to learn about DynamoDB? Check our article explaining how to use AWS Lambda so we can save data in Dynamo DB with examples.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/03\/aws-lambda-to-save-data-in-dynamodb.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2020\/03\/aws-lambda-to-save-data-in-dynamodb.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2020\/03\/aws-lambda-to-save-data-in-dynamodb.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","width":150,"height":150,"caption":"java-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2020\/03\/aws-lambda-to-save-data-in-dynamodb.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"AWS Lambda to save data in DynamoDB"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/58bd3e1f6edc1bed6a6374fe9a34ca37","name":"Gaurav Bhardwaj","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/657921afcac1f1ddf98dfb349121a07b4dcc1d42d5bd277150cf3ed8156de723?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/657921afcac1f1ddf98dfb349121a07b4dcc1d42d5bd277150cf3ed8156de723?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/657921afcac1f1ddf98dfb349121a07b4dcc1d42d5bd277150cf3ed8156de723?s=96&d=mm&r=g","caption":"Gaurav Bhardwaj"},"description":"Gaurav has done Masters in Computer Applications(MCA) and is working in Software development field for more than 10 years in Java\/J2EE technologies. He is currently working with one of top MNC. He has worked on various frameworks like Struts, Spring, Spring Boot, Angular JS, JSF, Velocity, iBatis, MyBatis, Hibernate, JUnit, Mockito, Dozzer. He likes to explore new technologies and share his thoughts by writing a technical blog. He is the founder of JavaSolutionsGuide.blogspot.com.","sameAs":["http:\/\/www.javasolutionsguide.blogspot.nl\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/gaurav-bhardwaj"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/103399","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/955"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=103399"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/103399\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/112"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=103399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=103399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=103399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}