The Geeky Asian

Everything You Need To Know

  • Home
  • Contact
  • Github
  • Discord Server

How to set up DynamoDB locally using Docker

July 27, 2021 by TheGeekyAsian Leave a Comment

ShareTweet

Lets have a look on how we can set up DynamoDB locally in 5 minutes!

How to set up DynamoDB locally using Docker

For one of my recent projects, I had to use DynamoDB. The client I was working for expected me to have a separate DynamoDB account. Meh.. He didn’t feel like providing me a DynamoDB instance on his AWS account, (security concerns, yeaahh!!) and I was too lazy to get one by myself.

That is when I found out that Amazon Web Services (AWS) provides a downloadable version of DynamoDB. It turned out to the best thing! Long story short, I was able to set up DynamoDB locally using Docker.

Here is a quick tutorial how you can do that:

Prerequisite

To be able to set up DynamoDB locally, you must have Docker installed on your local machine.

Install DynamoDB

Copy the below script and place it on your local machine in an empty file names docker-compose.yaml

version: '2'
services:
 dynamodb:
  image: amazon/dynamodb-local
  constainer_name: "dynamo_db"
  volumes:
   - ./dynamodb_data:/home/thegeekyasian/dynamodblocal/data
  command: -jar DynamoDBLocal.jar -sharedDb -dbPath /home/thegeekyasian/dynamodblocal/data/
  ports:
   - 8000:8000

Run DynamoDB

Once you have created the file with the above script, open the terminal/command line interface (CLI) and browse to the directory where you have created docker-compose.yaml file. In the CLI, execute the below command. It will then spin a DynamoDB container within the same directory and make a DynamoDB instance available for usage.

$ docker-compose up

Use the below command to stop the DynamoDB container

$ docker-compose down

How can I create a table in my local DynamoDB table?

The Local DynamoDB exposes a javascript-based command shell that allows you to create your desired table(s). Once the DynamoDB is started, you can find the shell at http://localhost:8000/shell as configured in the docker-compose.yaml file.

Here is a sample script to create a DynamoDB table using AWS Shell:

dynamodb.createTable({
	TableName: "the-geeky-asian-table",
	KeySchema: [
		{
			AttributeName: "id",
			KeyType: "HASH"
		}
	],
	AttributeDefinitions: [
		{
			AttributeName: "id",
			AttributeType: "S"
		}
	],
	ProvisionedThroughput: {
		ReadCapacityUnits: 1,
		WriteCapacityUnits: 1
	}
}, function(err, data) {
	if(err) ppJson(err);
	else ppJson(data);
});

And, done! You can now use this DynamoDB in any of your local projects and access it using the endpoint http://localhost:8000 from any service running locally on your machine.

Now that you are able to setup the DynamoDB in just 5 minutes, show some love in the comments and share this article with someone you think might get some help from this.

ShareTweet

Filed Under: How to? Tagged With: amazon dynamodb, aws, docker, dynamodb, dynamodb locally, install dynamodb, install dynamodb locally, set up dynamodb locally

Your thoughts? Feedback? Anything?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

How to?

  • WebSockets
  • JasperReports with Custom Fonts
  • Get Request with Body using RestTemplate

Like me?!

Copyright © 2025 · News Pro Theme on Genesis Framework · WordPress · Log in