I am trying to prototype a distributed application using SNS and SQS.I have this topic:
arn:aws:sns:us-east-1:574008783416:us-east-1-live-auction
and this queue:
arn:aws:sqs:us-east-1:574008783416:queue4
I created the queue using the JS Scratchpad. I added the subscription using the Console. I AddPermission to the queue using the scratchpad. The queue policy is now:
{ "Version":"2008-10-17", "Id":"arn:aws:sqs:us-east-1:574008783416:queue4/SQSDefaultPolicy", "Statement":[ { "Sid":"RootPerms", "Effect":"Allow", "Principal":{ "AWS":"574008783416" }, "Action":"SQS:*", "Resource":"arn:aws:sqs:us-east-1:574008783416:queue4" } ] }
I have an email subscription on the same topic and the emails arrive fine but the messages never arrive on the queue. I've tried SendMessage directly to the queue - rather than via SNS - using Scratchpad and it works fine. Any ideas why it won't send to the queue?
In the navigation pane, choose Queues. From the list of queues, choose the queue to subscribe to the SNS topic. From Actions, choose Subscribe to Amazon SNS topic. From the Specify an Amazon SNS topic available for this queue menu, choose the SNS topic for your queue.
To confirm the subscription, you can use the Amazon SQS console or the ReceiveMessage action. Before you subscribe an endpoint to the topic, make sure that the queue can receive messages from the topic by setting the sqs:SendMessage permission for the queue.
Go to the SNS topic and click on the "Create subscription" button to create a subscription. Here, change the protocol to Amazon SQS and specify the ARN of the SQS topic in the endpoint field. Check the "Enable raw message delivery" checkbox and then click on the "Create subscription" button.
This was posted a while back on the AWS forums: https://forums.aws.amazon.com/thread.jspa?messageID=202798
Then I gave the SNS topic the permission to send messages to the SQS queue. The trick here is to allow all principals. SNS doesn't send from your account ID -- it has its own account ID that it sends from.
Adding to Skyler's answer, if like me you cringe at the idea of allowing any principal (Principal: '*'
), you can restrict the principal to SNS:
Principal: Service: sns.amazonaws.com
Although this behavior is undocumented, it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With