{"id":60335,"date":"2024-02-15T18:32:52","date_gmt":"2024-02-15T13:02:52","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=60335"},"modified":"2024-02-20T18:40:26","modified_gmt":"2024-02-20T13:10:26","slug":"setting-up-amazon-dynamodb-locally-a-comprehensive-guide","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/setting-up-amazon-dynamodb-locally-a-comprehensive-guide\/","title":{"rendered":"Setting Up Amazon DynamoDB Locally: A Comprehensive Guide"},"content":{"rendered":"<h2><strong>Introduction<\/strong><\/h2>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">In modern application development, DynamoDB has emerged as a robust choice for managing NoSQL databases in the cloud. However, developers often need a local environment for testing, debugging, and even offline development. This blog will dive into setting up DynamoDB locally within a Java Spring Boot application, enabling seamless development and testing workflows.<\/span><\/p>\n<h2><strong>Prerequisites<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">Before we embark on our journey, ensure you have the following prerequisites:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Basic understanding of Java Spring Boot.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">JDK is installed on your machine.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Maven or Gradle for dependency management.<\/span><\/li>\n<\/ul>\n<p><strong>Two Paths to Setup DynamoDB locally:<\/strong><\/p>\n<ol>\n<li><b>Using <strong>DynamoDB Local<\/strong>: <\/b>DynamoDB Local is a downloadable version of DynamoDB that enables you to develop and test applications without connecting to the actual DynamoDB web service. It&#8217;s particularly useful for local development and testing scenarios where you want to simulate DynamoDB functionality without incurring costs or requiring internet access.<\/li>\n<li><b>Utilizing NoSQL Workbench:<\/b><span style=\"font-weight: 400;\"> Alternatively, developers can opt for NoSQL Workbench, a graphical tool provided by AWS. This approach offers a user-friendly interface for managing DynamoDB tables and data, making it suitable for those who prefer visual interaction or are new to DynamoDB.<\/span><\/li>\n<\/ol>\n<h2><strong>Java Springboot Configurations:<\/strong><\/h2>\n<p>Before starting, please set up the configuration below in your Java Springboot project for dynamoDB.<\/p>\n<ul>\n<li><strong>Add AWS SDK dependency to your Java Spring Boot project: <\/strong>\n<ul>\n<li><span style=\"font-weight: 400;\">To interact with DynamoDB in your Java Spring Boot application, you need to include the AWS SDK for DynamoDB as a dependency in your project&#8217;s configuration file (<\/span><span style=\"font-weight: 400;\">pom.xml<\/span><span style=\"font-weight: 400;\"> for Maven or <\/span><span style=\"font-weight: 400;\">build.gradle<\/span><span style=\"font-weight: 400;\"> for Gradle).<\/span><\/li>\n<li><strong>Example: pom.xml (Add below Dependency in your Spring project)<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">&lt;dependency&gt;<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0&lt;groupId&gt;com.amazonaws&lt;\/groupId&gt;<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0&lt;artifactId&gt;aws-java-sdk-dynamodb&lt;\/artifactId&gt;<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0&lt;version&gt;1.12.656&lt;\/version&gt;<\/span>\r\n<span style=\"font-weight: 400;\">&lt;\/dependency&gt;\r\n<\/span><\/pre>\n<ul>\n<li><strong>Configure the DynamoDB client in your Spring Boot application: <\/strong>\n<ul>\n<li><span style=\"font-weight: 400;\">After adding the SDK dependency, you need to configure the DynamoDB client in your Spring Boot application to connect to the locally running instance. This involves specifying the endpoint configuration for DynamoDB.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Configure DynamoDB in the Springboot application as below:<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div>\n<pre><strong>AWSDynamoDBConfig.java<\/strong><\/pre>\n<\/div>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60325 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/1-1-1024x463.png\" alt=\"Configuration\" width=\"625\" height=\"283\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/1-1-1024x463.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/1-1-300x136.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/1-1-768x347.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/1-1-624x282.png 624w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/1-1.png 1171w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><span style=\"font-weight: 400;\"><strong>application.properties<\/strong> (Add any Dummy data in access-key and secret-key)\u00a0<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60329 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/2-1.png\" alt=\"Application.properties\" width=\"817\" height=\"96\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/2-1.png 817w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/2-1-300x35.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/2-1-768x90.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/2-1-624x73.png 624w\" sizes=\"(max-width: 817px) 100vw, 817px\" \/><\/p>\n<p>Now that the configuration is complete, let&#8217;s set up DynamoDB locally.<\/p>\n<h2><b>1. Using <strong>DynamoDB Local<\/strong><\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Setting up with the <b><strong>DynamoDB Local<\/strong><\/b>:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><strong>Download DynamoDBLocal.jar:<\/strong>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Visit the AWS documentation page or GitHub repository to download the latest version of DynamoDBLocal.jar. or download it from <\/span><a href=\"https:\/\/d1ni2b6xgvw0s0.cloudfront.net\/v2.x\/dynamodb_local_latest.zip\"><span style=\"font-weight: 400;\">here <\/span><\/a><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Save the JAR file to a directory on your local machine and extract the contents.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400;\"><strong>Start DynamoDB Local:<\/strong>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Open your terminal or command prompt.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Navigate to the directory where you saved DynamoDBLocal.jar contents.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Run the following command to start DynamoDB Local:<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><strong style=\"color: #666666; font-family: Consolas, Monaco, 'Lucida Console', monospace; font-size: 0.857143rem; font-style: italic;\">java -Djava.library.path=.\/DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb<\/strong><\/pre>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><span style=\"font-weight: 400;\">Here, <strong>-Djava.library.path=.\/DynamoDBLocal_lib<\/strong><\/span><span style=\"font-weight: 400;\"> sets the path to the native libraries required by DynamoDB Local.<\/span><\/li>\n<li><strong>-jar DynamoDBLocal.jar -sharedDb<\/strong><span style=\"font-weight: 400;\"> starts DynamoDB Local with a shared database, allowing multiple connections.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60327 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/3-1.png\" alt=\"CMD\" width=\"1043\" height=\"254\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/3-1.png 1043w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/3-1-300x73.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/3-1-1024x249.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/3-1-768x187.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/3-1-624x152.png 624w\" sizes=\"(max-width: 1043px) 100vw, 1043px\" \/><\/p>\n<ul>\n<li><strong>AWS\u00a0 credential configuration:<\/strong>\n<ul>\n<li><span style=\"font-weight: 400;\">The next step is to run &#8220;<strong>$ aws configure<\/strong>&#8221; in the terminal. If you already have the credentials, simply press Enter. If you don&#8217;t have the credentials, you&#8217;ll need to provide the following details: (Add any Dummy data in access-key and secret-key) :<\/span><\/li>\n<li><span style=\"font-weight: 400;\">AWS Access Key ID<\/span><\/li>\n<li><span style=\"font-weight: 400;\">AWS Secret Access Key<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Default region-name<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Default output format<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60333 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/aws-config.png\" alt=\"aws\" width=\"844\" height=\"201\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/aws-config.png 844w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/aws-config-300x71.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/aws-config-768x183.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/aws-config-624x149.png 624w\" sizes=\"(max-width: 844px) 100vw, 844px\" \/><\/p>\n<ul>\n<li><strong>Interact with DynamoDB using the AWS SDK:<\/strong>\n<ul>\n<li><span style=\"font-weight: 400;\">With the Server started and AWS (dummy)credential configured, you can now interact with DynamoDB within your Spring Boot application or AWS command-line interface. This includes performing CRUD operations, querying and scanning tables, and any other operations your application requires.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2><b>2. Utilizing NoSQL Workbench<\/b><\/h2>\n<ul>\n<li><strong>Download and install NoSQL Workbench: <\/strong>\n<ul>\n<li>NoSQL Workbench is a graphical tool provided by AWS for interacting with DynamoDB. You can download and install it from the <a href=\"https:\/\/docs.aws.amazon.com\/amazondynamodb\/latest\/developerguide\/workbench.settingup.html\">AWS website<\/a>.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ul>\n<li><strong>Start DDB local in WorkBench:<\/strong>\n<ul>\n<li>As Shown below, start the DDB local server at the same port no described(8000) in the Java application.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-60330 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/Capture-1024x546.png\" alt=\"DDB\" width=\"625\" height=\"333\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/Capture-1024x546.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Capture-300x160.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Capture-768x409.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Capture-624x333.png 624w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/Capture.png 1366w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<ul>\n<li><strong>Configure a new connection to a local instance of DynamoDB:<\/strong>\n<ul>\n<li><span style=\"font-weight: 400;\"> Once DDB local starts, open the operation builder and configure a new connection to a local instance of DynamoDB. Provide the endpoint and port for your locally running DynamoDB instance.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60332 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/5-1-1024x608.png\" alt=\"Connection\" width=\"625\" height=\"371\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/5-1-1024x608.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/5-1-300x178.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/5-1-768x456.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/5-1-624x371.png 624w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/5-1.png 1226w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">\u00a0<strong>Use NoSQL Workbench&#8217;s graphical interface:<\/strong><\/span>\n<ul>\n<li><span style=\"font-weight: 400;\">With the connection configured, you can now use the NoSQL Workbench graphical interface for managing DynamoDB tables, inserting and updating data, running queries, and analyzing performance. You can also interact with DynamoDB within your Spring Boot application. You can create, edit, and delete tables, as well as perform advanced operations such as batch writes and exports.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60331 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/last-1024x546.png\" alt=\"CRUD\" width=\"625\" height=\"333\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/last-1024x546.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/last-300x160.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/last-768x409.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/last-624x333.png 624w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/last.png 1366w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>In conclusion, both DynamoDB Local and NoSQL Workbench provide convenient ways to set up DynamoDB locally for development and testing. Whether you prefer the command-line interface of DynamoDB Local or the graphical interface of NoSQL Workbench, you can select the method that aligns best with your workflow and development requirements.<\/p>\n<p><span style=\"font-weight: 400;\">Check out our other blog posts for more insights. <\/span><span style=\"font-weight: 400;\">If you still have questions, comment and join the discussion.<\/span><\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>Introduction In modern application development, DynamoDB has emerged as a robust choice for managing NoSQL databases in the cloud. However, developers often need a local environment for testing, debugging, and even offline development. This blog will dive into setting up DynamoDB locally within a Java Spring Boot application, enabling seamless development and testing workflows. Prerequisites [&hellip;]<\/p>\n","protected":false},"author":1669,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":581},"categories":[1174,446],"tags":[5305,2072],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/60335"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1669"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=60335"}],"version-history":[{"count":3,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/60335\/revisions"}],"predecessor-version":[{"id":60399,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/60335\/revisions\/60399"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=60335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=60335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=60335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}