Create DynamoDB tables locally from SAM Template yaml file

222 views Asked by At

How can I create tables a Dynamo DB locally using the same template.yaml file with AWS::Serverless-2016-10-31 definition for SAM/Cloud Formation that I intent to use for production?

DynamoDB is running locally using docker run -p 8000:8000 amazon/dynamodb-local but has no tables.

1

There are 1 answers

0
Andreas Lundgren On

By installing a CLI parser for yaml, example yq that reassembles the popular jq, you can run a linux command like this to configure your local Dynamo DB tables. This expects your DynamoDB to run on the standard port 8000 for local development:

aws dynamodb create-table --cli-input-yaml "`cat template.yaml | yq .Resources.[MY TABLE NAME].Properties`" --no-cli-pager --endpoint-url http://localhost:8000

Verify the creation using

aws dynamodb list-tables --endpoint-url http://localhost:8000