Created
May 23, 2019 09:08
-
-
Save sonjisov/b3787c9fed7a28873521e7ea21759640 to your computer and use it in GitHub Desktop.
Enabling DynamoDB stream settings on an existing table
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
region=$1 | |
# Quit on error | |
set -e | |
# 1. Update stream settings. | |
aws dynamodb update-table --table-name "JohnWickQuotes" --stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES --region $region |
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
region=$1 | |
functionName="quote-john-wick" | |
# Getting the stream name | |
streamArn="$(aws dynamodb describe-table --table-name "JohnWickQuotes" --region $region --output text --query 'Table.LatestStreamArn')" | |
# Check if a mapping already exists | |
mapping="$(aws lambda list-event-source-mappings --region us-east-1 --function-name $functionName --event-source-arn "$streamArn" --query 'EventSourceMappings[0]')" | |
if [[ $mapping = "null" ]] | |
then | |
# Subscribing the handler to a stream | |
aws lambda create-event-source-mapping \ | |
--region $region \ | |
--function-name $functionName \ | |
--event-source $streamArn \ | |
--batch-size 10 \ | |
--starting-position TRIM_HORIZON | |
else | |
echo "Mapping already exists." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment