Last active
March 28, 2018 19:35
-
-
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
This file contains hidden or 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
{ | |
"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" | |
} | |
} | |
] | |
} | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Need to make S3 ARN parametric, not hardcoded