如何提示AWS SNS向Cloudformation创建的订阅发送确认消息?

时间:2018-09-28 22:07:49

标签: amazon-web-services amazon-cloudformation amazon-sns

通过CloudFormation,我正在尝试创建一个队列并将其订阅到现有主题

$ cat ops/queue-and-subscription.yaml
AWSTemplateFormatVersion: 2010-09-09
Description: >-
  Minimal template

Resources:
  Queue:
    Type: 'AWS::SQS::Queue'

  Subscription:
    Type: 'AWS::SNS::Subscription'
    Properties:
      Endpoint:
        Fn::GetAtt:
          - "Queue"
          - "Arn"
      Protocol: "sqs"
      RawMessageDelivery: true
      TopicArn: "<existing Topic ARN>"

Outputs:
  QueueARN:
    Description: "ARN of the queue set up temporarily for testing"
    Value:
      Fn::GetAtt:
        - "Queue"
        - "Arn"
  QueueURL:
    Description: "URL of the queue. This is required for receiving messages"
    Value: !Ref Queue
$ aws cloudformation create-stack --stack-name my-test-stack --template-body file://ops/queue-and-subscription.yaml
{
    "StackId": "<stackId>"
}
[...wait...]
$ aws cloudformation describe-stacks --query 'Stacks[?StackName==`my-test-stack`] | [0].StackStatus'
"CREATE_COMPLETE"
$ aws cloudformation describe-stacks --query 'Stacks[?StackName==`my-test-stack`] | [0].Outputs[?OutputKey==`QueueURL`] | [0].OutputValue'
"<queueUrl>"
$ aws sqs receive-message --queue-url <queueUrl>
[null]

我希望将确认消息直接放在队列中(我需要阅读确认消息并将其传递给confirm-subscription调用docs。但是,从来没有这样的消息传递给队列

如何提示AWS(通过SDK,而不是UI)发送确认消息,以便我可以确认订阅?


编辑:我应该注意,我只是尝试了类似的方法,但是在模板中创建了SNS主题(并使用!Ref Topic进行了引用)-行为相同,没有确认消息。


EDIT2:我怀疑这是因为我没有提供SQS Queue Policy。现在尝试。

1 个答案:

答案 0 :(得分:0)

一旦我添加了QueuePolicy允许主题写入队列,消息就会按预期方式流过(没有确认消息)。