AWS SQS队列未收到SNS主题订阅的消息



在我的cloudformation模板中,我的SQS队列如下:

OutputQueuePolicy:
Type: AWS::SQS::QueuePolicy
Properties:
PolicyDocument:
Statement:
- Effect: "Allow"
Principal: "*"
Action:
- "sqs:SendMessage"
Resource:
Fn::GetAtt: [OutputQueue, Arn]
Condition:
ArnEquals:
aws:SourceArn: !Ref OutputTopic
Bool:
aws:SecureTransport: "false"
Queues:
- Ref: OutputQueue
OutputQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: isolation-change-output-queue
RedriveAllowPolicy:
redrivePermission: byQueue
sourceQueueArns:
- Fn::GetAtt: [OutputDeadLetterQueue, Arn]
RedrivePolicy:
deadLetterTargetArn:
Fn::GetAtt: [OutputDeadLetterQueue, Arn]
maxReceiveCount: 5
OutputDeadLetterQueuePolicy:
Type: AWS::SQS::QueuePolicy
Properties:
PolicyDocument:
Statement:
- Effect: "Deny"
Principal: "*"
Action:
- "sqs:SendMessage"
- "sqs:ReceiveMessage"
Resource: "*"
Condition:
Bool:
aws:SecureTransport: "false"
Queues:
- Ref: OutputDeadLetterQueue
OutputDeadLetterQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: isolation-change-output-dead-letter-queue

这是我的SNS主题:

OutputTopicPolicy:
Type: AWS::SNS::TopicPolicy
Properties:
PolicyDocument:
Statement:
- Sid: "Allow-SQS-to-receive-messages-from-topic"
Effect: "Allow"
Principal:
Service: "sqs.amazonaws.com"
Action: "sns:Publish"
Resource:
Ref: OutputTopic
Condition:
ArnEquals:
"aws:SourceArn":
Fn::GetAtt:
- OutputQueue
- Arn
Topics:
- Ref: OutputTopic
OutputTopic:
Type: AWS::SNS::Topic
Properties:
TopicName: isolation-change-output-topic
OutputQueueSNSSubscription:
Type: AWS::SNS::Subscription
Properties:
Endpoint:
Fn::GetAtt: [OutputQueue, Arn]
Protocol: "sqs"
RedrivePolicy:
deadLetterTargetArn:
Fn::GetAtt: [OutputDeadLetterQueue, Arn]
TopicArn: !Ref OutputTopic

我正试图通过AWS SDK向主题发布消息,但消息似乎没有进入队列。我没有收到任何错误,我不确定我的cloudformation模板出了什么问题。

您的Amazon SQS队列需要访问策略允许Amazon SNS Topic向Amazon SQS队列发送消息。

我部署了您的堆栈并将此策略添加到SQS队列:

{
"Version": "2008-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "sns.amazonaws.com"
},
"Action": "sqs:SendMessage",
"Resource": "arn:aws:sqs:ap-southeast-2:111111111111:isolation-change-output-dead-letter-queue",
"Condition": {
"ArnEquals": {
"aws:SourceArn": "arn:aws:sns:ap-southeast-2:111111111111:isolation-change-output-topic"
}
}
}
]
}

我可以成功地向SNS主题发送消息,该消息出现在SQS队列中。

策略复制自:订阅Amazon SQS队列到Amazon SNS主题- Amazon Simple Notification Service

您需要在OutputDeadLetterQueuePolicy中添加类似的策略。

相关内容

  • 没有找到相关文章

最新更新