Skip to content

Instantly share code, notes, and snippets.

@cmackenzie1
Last active October 12, 2024 08:33
Show Gist options
  • 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
@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