Last active
August 24, 2019 22:41
-
-
Save me2resh/c33e1fa6c659115e0d94d19945e18d41 to your computer and use it in GitHub Desktop.
Attach Event to a bucket in a different stack, Sometimes you need to attach an event to a bucket that don't exist in your project stack, You can run this shell script to achieve that
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/bash | |
# Get function ARN from stack | |
FUNCNAME="MyFunctionName" | |
FUNCARN=$(aws cloudformation describe-stacks \ | |
--stack-name "Stack-Name" \ | |
--query "Stacks[0].Outputs[?OutputKey==${FUNCNAME}].OutputValue" --output text | |
) | |
echo $FUNCARN | |
JSON=$(cat <<-EOF | |
{ | |
"LambdaFunctionConfigurations": [ | |
{ | |
"Id": "EventName", | |
"LambdaFunctionArn": ${FUNCARN}, | |
"Events": [ | |
"s3:ObjectCreated:*" | |
] | |
} | |
] | |
} | |
EOF | |
) | |
aws --profile sandbox s3api \ | |
put-bucket-notification-configuration \ | |
--bucket="bucket-name" \ | |
--notification-configuration "$JSON" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment