Skip to content

Instantly share code, notes, and snippets.

@marcogrcr
Created November 7, 2024 13:35
Show Gist options
  • Save marcogrcr/5198014b44f549c908dd53b0e13595ba to your computer and use it in GitHub Desktop.
Save marcogrcr/5198014b44f549c908dd53b0e13595ba to your computer and use it in GitHub Desktop.
Create a DynamoDB table using localstack
#!/bin/sh
set -eu
echo 'Initializing test DynamoDB table...'
# https://docs.localstack.cloud/getting-started/installation/#docker
IMAGE=$(docker run \
--rm -d \
-p 127.0.0.1:4566:4566 \
-p 127.0.0.1:4510-4559:4510-4559 \
-v /var/run/docker.sock:/var/run/docker.sock \
localstack/localstack:3.2.0)
sleep 3
aws \
--region us-east-1 \
--endpoint-url http://127.0.0.1:4566 \
dynamodb create-table \
--table-name single-table \
--key-schema '[{"AttributeName":"pk","KeyType":"HASH"},{"AttributeName":"sk","KeyType":"RANGE"}]' \
--attribute-definitions '[{"AttributeName":"pk","AttributeType":"S"},{"AttributeName":"sk","AttributeType":"S"}]' \
--billing-mode PAY_PER_REQUEST \
> /dev/null
handle_sigint() {
echo ''
echo 'Cleaning up...'
docker stop "$IMAGE" > /dev/null
echo 'Cleaned up successfully!'
exit 0
}
trap handle_sigint SIGINT
echo 'Table initialized successfully! Press CTRL+C to cleanup.'
while true; do
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment