Docker images
On this page, you can find some relevant Docker images. This might be useful for local development or for integration testing.
amazon/dynamodb-local
The official Docker image provided by Amazon to run DynamoDB locally.
Example of a compose.yaml
, exposing it on port 4567 of your host:
services:
dynamodb:
command: "-jar DynamoDBLocal.jar -sharedDb -inMemory"
image: "amazon/dynamodb-local:latest"
ports:
- "4567:8000"
Note that this will not initialize any tables. To do so, you could set up another service that initializes your table based on a JSON schema, using the AWS CLI. Example:
services:
dynamodb:
command: "-jar DynamoDBLocal.jar -sharedDb -inMemory"
image: "amazon/dynamodb-local:latest"
ports:
- "4567:8000"
healthcheck:
test:
[
"CMD-SHELL",
'[ "$(curl -s -o /dev/null -I -w ''%{http_code}'' http://localhost:8000)" == "400" ]',
]
interval: 5s
timeout: 10s
retries: 3
dynamodb-setup:
image: "amazon/aws-cli:latest"
volumes:
- "./app/resources/dynamodb-schemas:/tmp/dynamo"
depends_on:
dynamodb:
condition: service_healthy
environment:
AWS_ACCESS_KEY_ID: "FAKEID"
AWS_SECRET_ACCESS_KEY: "FAKEKEY"
AWS_REGION: "eu-west-1"
entrypoint:
- bash
command: '-c "for f in /tmp/dynamo/*.schema.json; do aws dynamodb create-table --endpoint-url "http://dynamodb:8000" --cli-input-json file://"$${f#./}"; done"'
This will mount your local directory app/resources/dynamodb-schemas
and search for *.schema.json
files to create tables.
For example, a my-table.schema.json
:
{
"TableName": "MyTable",
"AttributeDefinitions": [
{
"AttributeName": "foo",
"AttributeType": "S"
},
{
"AttributeName": "bar",
"AttributeType": "S"
}
],
"KeySchema": [
{
"AttributeName": "foo",
"KeyType": "HASH"
},
{
"AttributeName": "bar",
"KeyType": "RANGE"
}
],
"BillingMode": "PAY_PER_REQUEST"
}
wiremock/wiremock
A Docker version of WireMock, useful to mock remote endpoints.
Example of a compose.yaml
, exposing it on port 8081 of your host:
services:
wiremock:
image: "wiremock/wiremock:latest"
ports:
- "8081:8080"
To interact with WireMock from a Vitest script, we recommend WireMock Captain.
localstack/localstack
LocalStack is a fully functional local AWS cloud stack that allows you to develop and test cloud applications on your local machine without actually using AWS services. It emulates a wide range of AWS services such as S3, Lambda, DynamoDB, SQS, SNS, API Gateway, and many more.
Example of compose.yaml
with LocalStack, mounting some DynamoDB schemas from ./app/resources/dynamodb-schemas
and running ./init-aws-local.sh
. It has a custom health check added that waits for the init script to be completed.
services:
localstack:
image: localstack/localstack
volumes:
- "./app/resources/dynamodb-schemas:/tmp/dynamo"
- "./init-aws-local.sh:/etc/localstack/init/ready.d/init-aws.sh"
environment:
- DYNAMODB_IN_MEMORY=1
- DYNAMODB_SHARE_DB=1
ports:
- '4566:4566'
- '4510-4559:4510-4559'
healthcheck:
test: >
curl -s http://localhost:4566/_localstack/init/ready | grep -q '"completed": true'
interval: 5s
timeout: 5s
start_period: 1m
retries: 5
Example of ./init-aws-local.sh
, using awslocal from LocalStack.
#!/bin/bash
for f in /tmp/dynamo/*.schema.json; do
awslocal dynamodb create-table --cli-input-json file://"${f#./}";
done
awslocal s3api create-bucket --bucket my-bucket