How to use dynamodb locally using docker image - aws


 This blog will show you how to use dynamodb locally to test it locally during development and to avoid cost of real time AWS web services.

i am using window 10 and docker for window then switch this docker to linux

Prerequisites:

    Docker 

    dynamodb image 

Follow the steps: 

        I am using window so i will talk more scenario with window.

Step 1: if you don't have docker install on your computer then install it you can use docker official website to download this according to your operation system.  to verify open you command prompt and then type docker -v to verify docker is installed

Step 2:  Now copy the below image and the compose this image you can chose many other way to compose a file (docker-compose.yml)

Docker-compose up 

This  command can use to compose docker file we will talk this cmd  later. both below commands can be used to run docker and pull the image of dynamodb

    docker run -p 8000:8000 cnadiminti/dynamodb-local  -sharedDb -dbPath /tmp   
    //docker command without shareddb instance
    docker run -p 8000:8000 amazon/dynamodb-local 

 if you want to pass arguments like sahredDb or other use 1st cmd.

Alternate way with LocalStack  image

There is another way to use dynamodb and other aws services locally with localstack image. 

localstack expose many services of aws like s3, dynamodb , ses etc...

Create a file docker-compose.yml and the paste the below code to that file, on the same directory where this file is save open cmd with that directory and run the 

docker-compose up

Compose file with VSCODE  

There is another and easy way to compose and manage this file with vs code

Open the file in vscode and the right click on the file code and then find and click compose up option. it will build and run you docker image into docker container 

>>> file docker-compose.yml

version'3.7'
services:
  localstack-dynamodb :
    imagelocalstack/localstack:latest
    container_namelocalstack-dynamodb
    environment:
     - SERVICES=dynamodb:4564
     - DEFAULT_REGION=us-west-2
     - DATA_DIR=/tmp/localstack/data
    ports:
     - "8000:4564"
    volumes:
      - localstack-data:/tmp/localstack
volumes:
  localstack-data:
    namelocalstack-data


To check the docker image is successfully build and run use this cmd
docker ps



Comments