简体   繁体   English

aws cloudformation 模板 sns sqs

[英]aws cloudformation template sns sqs

I've defined an SNS topic, an SQS queue, and an SNS subscription resource in a Cloudformation stack.我在 Cloudformation 堆栈中定义了一个 SNS 主题、一个 SQS 队列和一个 SNS 订阅资源。 All three are in the same stack, same region, and same AWS account.这三个都在同一个堆栈、同一个区域和同一个 AWS 账户中。

Resources:
  SqsQueue:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: 'some-queue'
  SnsTopic:
    Type: AWS::SNS::Topic
    Properties:
      TopicName: 'some-topic'
  SnsSubscription:
    Type: AWS::SNS::Subscription
    Properties:
      Endpoint: !GetAtt [SqsQueue, Arn]
      Protocol: sqs
      TopicArn: !Ref SnsTopic

When I run the stack, all three resources are created successfully, but when I publish a message from SNS, it's never received by the SQS queue.当我运行堆栈时,所有三个资源都已成功创建,但是当我从 SNS 发布消息时,SQS 队列从未收到它。

I've been following this link ( https://aws.amazon.com/premiumsupport/knowledge-center/sqs-sns-subscribe-cloudformation/ ) and to my knowledge I've done everything I've needed to.我一直在关注这个链接( https://aws.amazon.com/premiumsupport/knowledge-center/sqs-sns-subscribe-cloudformation/ ),据我所知,我已经完成了我需要做的一切。 What else am I missing?我还缺少什么?

Thanks!谢谢!

Additional info附加信息

  • If I delete the subscription that Cloudformation created via the console and then create a new one via the console, messages are published fine.如果我删除 Cloudformation 通过控制台创建的订阅,然后通过控制台创建一个新订阅,则可以正常发布消息。 So it must be something incorrect about the subscription.所以订阅一定有问题。

  • I used the AWS CLI to compare the properties of the subscription created by the Cloudformation template to the one created by the console.我使用 AWS CLI 将 Cloudformation 模板创建的订阅属性与控制台创建的属性进行比较。 They are the exact same.它们完全相同。

You need to add a policy to allow the SNS topic to publish to your queue.您需要添加策略以允许 SNS 主题发布到您的队列。 Something like this:像这样的东西:

  SnsToQueuePolicy:
    Type: AWS::SQS::QueuePolicy
    Properties: 
      Queues:
        - !Ref SqsQueue
      PolicyDocument: 
        Version: '2012-10-17'
        Statement:
          - Sid: allow-sns-messages
            Effect: Allow
            Principal: '*'
            Resource: !GetAtt SqsQueue.Arn
            Action: SQS:SendMessage,
            Condition: 
              ArnEquals:
                aws:SourceArn: !Ref SnsTopic

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM