After going through the docs, I wrote the following cloud-formation template to create en SNS topic, an SQS topic and subscribe the topic to the SQS queue:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Creates the SNS topic, SQS queue and instance that will service the custom resources queue",
"Parameters": {
"Environment": {
"Description": "Environment in which to manage queues",
"Type": "String",
"Default": "qa",
"AllowedValues": [ "development", "qa", "staging", "production"]
},
"EmailAddress": {
"Description": "Email to where notifications will be sent",
"Type": "String",
"Default": "[email protected]"
}
},
"Resources": {
"CustomResourcesQueue": {
"Type": "AWS::SQS::Queue",
"Properties": {
"ReceiveMessageWaitTimeSeconds": 20,
"VisibilityTimeout": 60,
"QueueName": {
"Fn::Join": ["-", ["cloud_formation_custom_resources", {
"Ref": "Environment"
}]]
}
}
},
"CustomResourcesTopic": {
"Type": "AWS::SNS::Topic",
"Properties": {
"Subscription": [
{
"Endpoint": {
"Ref": "EmailAddress"
},
"Protocol": "email"
},
{
"Endpoint": {
"Fn::GetAtt": ["CustomResourcesQueue", "Arn"]
},
"Protocol": "sqs"
}
]
}
},
"SNSToSQSPolicy": {
"Type": "AWS::SQS::QueuePolicy",
"Properties": {
"PolicyDocument": {
"Id": "PushMessageToSQSPolicy",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "allow-sns-to-send-message-to-sqs",
"Effect": "Allow",
"Action": [ "sqs:*" ],
"Principal": {
"AWS": "*"
},
"Resource": {
"Ref": "CustomResourcesTopic"
},
"Condition": {
"StringEquals": {
"aws:SourceArn": {
"Ref": "CustomResourcesTopic"
}
}
}
}
]
},
"Queues": [
{
"Ref": "CustomResourcesQueue"
}
]
}
}
}
}
The cloud-formation is successfully created, but whenever I publish a message to the SNS topic, I only get the email, the message never arrives at the SQS queue.
Am I missing something at the policy here? Is there some other way to use cloud-formations to tie SNS and SQS?