Reputation: 5412
so far I have set up an SNS topic with 2 SQS subscriptions to it. Each SQS has a lambda trigger associated with it.
When I send the message via SNS.publish like this to send message to the 2nd SQS subscription:
response = sns.publish(
TopicArn='arn:aws:sns:us-west-2:234723472:test',
Message=json.dumps({'default': json.dumps({"c": code, "event_type": queuename})}),
MessageAttributes={'event_type':{'DataType':'String', 'StringValue':queuename}
)
the queue remains empty.
yet, when I send a message directly to the queue, the lambda trigger works. But the messages seem to be not getting past once sent to SNS. No errors is triggered. It's frustrating that SNS doesn't show a log of messages it received so I can't really debug things here.
What could I be missing?
I also tried with and without MessageStructure='json'
above and it made no difference.
It's frustrating not knowing where the silent error is happening in AWS.
Upvotes: 2
Views: 1758
Reputation: 1034
I had the same problem. Please check if you have permissions set on SQS, so it can accept messages from the SNS.
Example:
# SQS Queue
MyQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: MyQueue
# SNS Topic
MyTopic:
Type: AWS::SNS::Topic
Properties:
TopicName: MyTopic
# Topic Subscription
MyTypicSubscription:
Type: AWS::SNS::Subscription
Properties:
Endpoint: !GetAtt MyQueue.Arn
Protocol: sqs
RawMessageDelivery: true
TopicArn: !Ref MyTopic
#Permissions for SQS to receive SNS notifications
MyQueuePermissions:
Type: AWS::SQS::QueuePolicy
Properties:
PolicyDocument:
Statement:
Effect: Allow
Principal:
AWS: '*'
Action: SQS:SendMessage
Resource:
- !GetAtt MyQueue.Arn
Condition:
ArnEquals:
aws:SourceArn: !Ref MyTopic
Queues:
- !Ref MyQueue
In console it looks like this:
The SNS service notifies its subscribers but "doesn't care" if the subscriber is available or not, hence no error message on SNS. Hope that helps!
Upvotes: 3