Skip to content

Instantly share code, notes, and snippets.

@cmackenzie1
Last active April 26, 2024 16:38
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save cmackenzie1/92e0c3628da6842f0e9ffeca8abbe170 to your computer and use it in GitHub Desktop.
Save cmackenzie1/92e0c3628da6842f0e9ffeca8abbe170 to your computer and use it in GitHub Desktop.
Docker Compose for DynamoDB Local and Admin UI
version: '3.7'
services:
dynamodb-local:
image: amazon/dynamodb-local:latest
container_name: dynamodb-local
ports:
- "8000:8000"
dynamodb-admin:
image: aaronshaf/dynamodb-admin
ports:
- "8001:8001"
environment:
DYNAMO_ENDPOINT: "http://dynamodb-local:8000"
AWS_REGION: "us-west-2"
AWS_ACCESS_KEY_ID: local
AWS_SECRET_ACCESS_KEY: local
depends_on:
- dynamodb-local
@toderesa97
Copy link

This is really weird. I am connecting to the dynamodb instance from the SDK specifying endpoint_url=http://localhost:8000 parameter, and I don't get to see the tables in the UI.

@cmackenzie1
Copy link
Author

cmackenzie1 commented Oct 16, 2021

@toderesa97

This is really weird. I am connecting to the dynamodb instance from the SDK specifying endpoint_url=http://localhost:8000 parameter, and I don't get to see the tables in the UI.

I just pulled the latest images for this compose-file and tried to reproduce. I was able to resolve the issue by specifying the following environment variables additional variables on the dynamodb-admin container.

version: '3.7'
services:
  dynamodb-local:
    image: amazon/dynamodb-local:latest
    container_name: dynamodb-local
    ports:
      - "8000:8000"

  dynamodb-admin:
    image: aaronshaf/dynamodb-admin
    ports:
      - "8001:8001"
    environment:
      DYNAMO_ENDPOINT: "http://dynamodb-local:8000"
      AWS_REGION: "us-west-2"
      AWS_ACCESS_KEY_ID: local
      AWS_SECRET_ACCESS_KEY: local
    depends_on:
      - dynamodb-local

Double check the region matches and you set some local credentials (and use them in the SDK in addition to the endpoint parameter.)

Thanks for catching this :) I'll update the gist!

@lawson-ng
Copy link

@cmackenzie1 Can you let me know why we have to specifying DYNAMO_ENDPOINT instead of localhost ? Sorry Im a newbie.

@cmackenzie1
Copy link
Author

@cmackenzie1 Can you let me know why we have to specifying DYNAMO_ENDPOINT instead of localhost ? Sorry Im a newbie.

No worries! I specified DYNAMO_ENDPOINT due to how Docker Compose creates networks. The Docker docs have a good overview of what it does when using docker-compose https://docs.docker.com/compose/networking/.

The tl;dr is localhost doesn't always resolve to your actual local machine network adapter.

@lawson-ng
Copy link

@cmackenzie1 Can you let me know why we have to specifying DYNAMO_ENDPOINT instead of localhost ? Sorry Im a newbie.

No worries! I specified DYNAMO_ENDPOINT due to how Docker Compose creates networks. The Docker docs have a good overview of what it does when using docker-compose https://docs.docker.com/compose/networking/.

The tl;dr is localhost doesn't always resolve to your actual local machine network adapter.

Thank you so much for you explanation. 😊

@mxmzb
Copy link

mxmzb commented Dec 26, 2021

Double check the region matches and you set some local credentials (and use them in the SDK in addition to the endpoint parameter.)

@cmackenzie1 What should the region match to? Does this relate to the region we set up in aws configure or... ?

@cmackenzie1
Copy link
Author

@mxmzb it would depend on your specific setup. The AWS SDK (in the language of your choice) should at least specify the same region as the configured Docker container.

If you are relying on profiles in your ~/.aws/credentials file, then the region for the selected profile would need to match.

@njlr
Copy link

njlr commented Apr 26, 2024

I was unable to see tables created by different scripts until I enabled sharedDb mode.

Note the command property...

version: '3.9'
services:

  dynamodb:
    image: amazon/dynamodb-local:2.4.0
    command: "-jar DynamoDBLocal.jar -sharedDb"
    healthcheck:
      test: [ "CMD-SHELL", "curl -v http://dynamodb:8000" ]
      interval: 3s
      timeout: 3s
      retries: 5
      start_period: 3s
    ports:
      - "8000:8000"
    restart: always

  dynamodb-admin:
    image: aaronshaf/dynamodb-admin:4.6.1
    ports:
      - "8001:8001"
    environment:
      DYNAMO_ENDPOINT: "http://dynamodb:8000"
      AWS_REGION: "eu-west-2"
      AWS_ACCESS_KEY_ID: abc
      AWS_SECRET_ACCESS_KEY: def
    depends_on:
      dynamodb:
        condition: service_healthy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment