Adding DynamoDB Local to DDEV

A quick guide on adding Amazon DynamoDB Local to your DDEV environment for local development.

Create .ddev/docker-compose.dynamodb.yaml

services:
  dynamodb:
    image: amazon/dynamodb-local:latest
    container_name: ddev-${DDEV_SITENAME}-dynamodb
    command: "-jar DynamoDBLocal.jar -sharedDb -inMemory"
    ports:
      - "8000:8000"
    labels:
      com.ddev.site-name: ${DDEV_SITENAME}
      com.ddev.approot: ${DDEV_APPROOT}

Create .ddev/commands/web/dynamodb-init

#!/bin/bash
## Description: Initialize DynamoDB tables
## Usage: dynamodb-init
## Example: ddev dynamodb-init

export AWS_ACCESS_KEY_ID=local
export AWS_SECRET_ACCESS_KEY=local

ENDPOINT="http://dynamodb:8000"
REGION="us-east-1"

echo "Initializing DynamoDB tables..."

# Create your tables here
aws dynamodb create-table \
    --table-name my_table \
    --attribute-definitions AttributeName=id,AttributeType=S \
    --key-schema AttributeName=id,KeyType=HASH \
    --billing-mode PAY_PER_REQUEST \
    --endpoint-url $ENDPOINT \
    --region $REGION \
    --no-cli-pager

echo "Done."

Make it executable:

chmod +x .ddev/commands/web/dynamodb-init

Configure post-start hook in .ddev/config.yaml

hooks:
  post-start:
    - exec-host: ddev dynamodb-init

Restart DDEV

ddev restart

Verify installation

ddev exec aws dynamodb list-tables \
    --endpoint-url http://dynamodb:8000 \
    --region us-east-1

Connecting from your app

Use endpoint http://dynamodb:8000 with dummy credentials:

  • AWS_ACCESS_KEY_ID=local
  • AWS_SECRET_ACCESS_KEY=local
  • AWS_DEFAULT_REGION=us-east-1

Note: The -inMemory flag means data is lost on container restart. Remove it and add a volume mount if you need persistence.

Use NoSQL Workbench for DynamoDB to explore database locally.

********************************** ************************* ************************ **************** ****************** *********** ************** ************* ************ *************