How to use aws-cli with local dynamoDB ?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Amazon Web Services Command Line Interface (AWS CLI) is a unified tool that allows users to interact with AWS services, including DynamoDB, a NoSQL database service. This article focuses on using AWS CLI with a local instance of DynamoDB. Using DynamoDB locally can be beneficial for development and testing purposes without incurring costs.
Prerequisites
Before diving into AWS CLI with local DynamoDB, ensure the following are installed on your machine:
- AWS CLI: You can install it by following the instructions provided here.
- Java: Required to run local DynamoDB. Install Java from this link.
- Local DynamoDB: Downloadable as a JAR file from the AWS DynamoDB local page.
Once these tools are in place, you can proceed to set up and use DynamoDB locally.
Setting Up Local DynamoDB
Step 1: Running DynamoDB Locally
Extract the downloaded .zip file for DynamoDB Local. Navigate to the extracted directory and run the following command to start DynamoDB:
The -sharedDb flag ensures that all requests are directed to a single database instance, useful for development environments.
Step 2: Configuring AWS CLI
Configure AWS CLI to work with the local version of DynamoDB. Specifically, you'll change the endpoint URL to point to the local DynamoDB. Use the AWS CLI configure command:
During this process, provide dummy AWS Access Key and Secret Key, as local DynamoDB doesn't require actual keys. Ensure the Region is set (e.g., us-west-2), and output format (e.g., json).
AWS CLI Operations on Local DynamoDB
Below are examples of basic operations you can perform on a local DynamoDB instance using AWS CLI:
Creating a Table
To create a table named MusicCollection with Artist as the partition key, use the following command:
Inserting Data
To put an item into the MusicCollection table:
Querying Data
To retrieve an item by its partition key:
Deleting a Table
To delete the table:
Troubleshooting
Connectivity Issues
Ensure that DynamoDB Local is running on http://localhost:8000. If not, review your initial setup command and try running it again.
AWS CLI Errors
If you run into errors regarding credentials, double-check your AWS config file. Running DynamoDB locally does not require valid AWS credentials but ensures no syntax errors exist in your configuration.
Summary Table
| Operation | AWS CLI Command Example | Endpoint |
| Create Table | aws dynamodb create-table ... | http://localhost:8000 |
| Insert Item | aws dynamodb put-item ... | http://localhost:8000 |
| Query Item | aws dynamodb get-item ... | http://localhost:8000 |
| Delete Table | aws dynamodb delete-table ... | http://localhost:8000 |
| Configuration | aws configure (with dummy credentials) | N/A |
Conclusion
Leveraging AWS CLI with local DynamoDB greatly enhances the development and testing pipeline by simulating AWS services without cost. By following the instructions above, you can set up and interact with DynamoDB locally, performing CRUD operations using AWS CLI. For a complete list of operations and advanced configurations, refer to the AWS CLI and DynamoDB documentation.
Related reading
- How to use AWS account_id variable in Terraform
- How to use AWS IoT to send/receive messages to/from Web Browser
- How to use aws nlb with nginx ingress controller for ssl
- How to use AWS S3 CLI to dump files to stdout in BASH?
- How to use AWS SDK C XRay in a AWS Lambda Layer implemented in C called by a Lambda function in Python?
- How to use AWS SQS/SNS as a push notification queue for heavy processing tasks via PHP?
- How to use awscli inside python script?
- How to use begins_with in AWS DynamoDb js sdk?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.