Created
November 7, 2024 13:35
-
-
Save marcogrcr/5198014b44f549c908dd53b0e13595ba to your computer and use it in GitHub Desktop.
Create a DynamoDB table using localstack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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