Skip to content

Instantly share code, notes, and snippets.

@me2resh
Last active August 24, 2019 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save me2resh/c33e1fa6c659115e0d94d19945e18d41 to your computer and use it in GitHub Desktop.
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
#!/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