I am trying to develop a Lambda API to interact with DynamoDB, but I'm having issues with my local testing setup.
I'm using AWS SAM for development, but for some reason my local API server (using sam local start-api
) can't connect to the DynamoDB Local instance running inside Docker. I have been able to call the DynamoDB Local endpoint, http://localhost:8000, with the AWS CLI, however as I understand it due to the network bridge I need to use the container name for the endpoint.
Here's the error I'm getting:
"errorMessage":"Inaccessible host: `ddb-local' at port `undefined'. This service may not be available in the `localhost' region.
Here's the config I'm using:
docClient = new dynamodb.DocumentClient({
accessKeyId: "0600k",
secretAccessKey: "k3hwkb",
region: "localhost",
endpoint: "http://ddb-local/:8000",
});
And here's the docker-compose.yml:
version: '3.8'
services:
dynamodb-local:
command: "-jar DynamoDBLocal.jar -sharedDb -optimizeDbBeforeStartup -dbPath ./data"
image: "amazon/dynamodb-local:latest"
container_name: ddb-local
ports:
- "8000:8000"
volumes:
- "./docker/dynamodb:/home/dynamodblocal/data"
working_dir: /home/dynamodblocal
How can I successfully connect the two services?