Skip to content

Instantly share code, notes, and snippets.

@sonjisov
Created May 23, 2019 09:08
Show Gist options
  • Save sonjisov/b3787c9fed7a28873521e7ea21759640 to your computer and use it in GitHub Desktop.
Save sonjisov/b3787c9fed7a28873521e7ea21759640 to your computer and use it in GitHub Desktop.
Enabling DynamoDB stream settings on an existing table
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
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