Skip to content

Instantly share code, notes, and snippets.

@shentonfreude
Last active March 28, 2018 19:35
Show Gist options
  • Save shentonfreude/d7e210f4f560f9f5f5c9 to your computer and use it in GitHub Desktop.
Save shentonfreude/d7e210f4f560f9f5f5c9 to your computer and use it in GitHub Desktop.
S3 bucket with Notification to SNS which sends email and injects a message into SQS
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Apply policy to NEW bucket",
"Resources": {
"Queue": {
"Type": "AWS::SQS::Queue",
"Properties": {
"QueueName": "cshenton-tropo-queue"
}
},
"QueuePolicy": {
"Type": "AWS::SQS::QueuePolicy",
"Properties": {
"Queues": [{"Ref": "Queue"}],
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Allow-SNS-Topic-to-SendMessage-to-SQS-Queue",
"Effect": "Allow",
"Principal": { "AWS": "*" },
"Action": "sqs:SendMessage",
"Resource": {"Fn::GetAtt": ["Queue", "Arn"]},
"Condition": {
"ArnEquals": {
"aws:SourceArn": {"Ref": "Topic"}
}
}
}
]
}
}
},
"Topic": {
"Type": "AWS::SNS::Topic",
"Properties": {
"Subscription": [
{
"Endpoint": "[email protected]",
"Protocol": "email"
},
{
"Endpoint": {"Fn::GetAtt": ["Queue", "Arn"]},
"Protocol": "sqs"
}
]
}
},
"TopicPolicy": {
"Type" : "AWS::SNS::TopicPolicy",
"Properties": {
"Topics": [{"Ref": "Topic"}],
"PolicyDocument": {
"Version": "2008-10-17",
"Id": "example-ID",
"Statement": [
{
"Sid": "topic-sid",
"Effect": "Allow",
"Principal": {"Service": "s3.amazonaws.com"},
"Action": ["SNS:Publish"],
"Resource": {"Ref": "Topic"},
"Condition": {
"ArnLike": {
"aws:SourceArn": "arn:aws:s3:*:*:cshenton-tropo-bucket-with-policy"
}
}
}
]
}
}
},
"Bucket": {
"Type": "AWS::S3::Bucket",
"Properties": {
"AccessControl": "BucketOwnerFullControl",
"BucketName": "cshenton-tropo-bucket-with-policy",
"NotificationConfiguration": {
"TopicConfigurations": [
{
"Event": "s3:ObjectCreated:*",
"Topic": {
"Ref": "Topic"
}
}
]
}
}
}
}
}
@shentonfreude
Copy link
Author

Need to make S3 ARN parametric, not hardcoded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment