首页 文章

是否可以在不创建主题的情况下使用CloudFormation创建SNS订阅?

提问于
浏览
11

是否可以在AWS CloudFormation JSON模板中创建'Subscription'资源而无需创建新的 AWS::SNS::Topic

在我的例子中,主题是在CloudFormation脚本之外创建的,我想创建一些订阅,涉及在脚本中创建的资源 .

I.E.

"DbfExtractQueue": {
        "Type": "AWS::SQS::Queue"
    },

    "EtlSubscription": {
        "Type": "AWS::SNS::Subscription",
        "Properties": {
            "Endpoint": { "Fn::GetAtt": ["DbfExtractQueue", "Arn"] },
            "Protocol": "sqs",
            "TopicArn": { "Ref": "EtlNotificationTopicARN" }
        }
    },

EtlNotificationTopicARN被传递到脚本中并表示SNS主题ARN .

3 回答

  • 9

    正如您已经发现的那样,AWS CloudFormation没有提供预期的 AWS::SNS::Subscription 资源(并且)我可以使用(也许他们会在某些时候添加它,AWS通常会随着时间的推移扩展他们的API来解决这些不一致/缺失) .

  • 3

    现在可以在2016年11月直接在原生CloudFormation中执行此操作:

    http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sns-subscription.html

    以上文档中的示例 .

    YAML:

    MySubscription:
      Type: AWS::SNS::Subscription
      Properties:
        Endpoint: test@email.com
        Protocol: email
        TopicArn: !Ref 'MySNSTopic'
    

    JSON:

    "MySubscription" : {
      "Type" : "AWS::SNS::Subscription",
      "Properties" : {
        "Endpoint" : "test@email.com",
        "Protocol" : "email",
        "TopicArn" : {"Ref" : "MySNSTopic"}
      }
    }
    
  • 0

    现在可以使用CloudFormation支持具有Lambda函数的自定义资源类型 .

    我在这里用CloudFormation模板创建了一个要点:https://gist.github.com/martinssipenko/4d7b48a3d6a6751e7464.js

相关问题