如何使用AWS CloudFormation为SNS订阅指定“原始消息传递”? [英] Howto specify 'Raw Message Delivery' for an SNS subscription using AWS CloudFormation?

查看:116
本文介绍了如何使用AWS CloudFormation为SNS订阅指定“原始消息传递”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 AWS CloudFormation 模板,用于创建SNS主题和订阅:

I've got an AWS CloudFormation template that creates an SNS topic and a subscription:

"AcceptedTopic":{
            "Type": "AWS::SNS::Topic",
            "Properties": {
                "DisplayName": {"Fn::Join": ["", ["Accepted-", {"Ref": "Env"}]]},
                "TopicName": {"Fn::Join": ["", ["Accepted-", {"Ref": "Env"}]]},
                "Subscription": [{
                    "Endpoint": {"Fn::GetAtt" : [ "SomeQueue" , "Arn" ]},
                    "Protocol": "sqs"
                }]
            }
        }

我需要指定原始消息传递订阅属性。如何在 AWS CloudFormation 中做到这一点?

I need to specify the 'Raw Message Delivery' subscription attribute. How can I do that in AWS CloudFormation?

推荐答案

现在,AWS CloudFormation支持 AWS :: SNS :: Subscription 。因此,与其将订阅添加为主题的属性,不如添加上面链接的订阅资源。

Now AWS CloudFormation supports it with AWS::SNS::Subscription. So instead of adding the subscription as a property of the topic, add an Subscription resource linked above.

不过要注意的是,如果您已经使用该订阅创建了主题并且现在正在尝试添加属性,由于无效参数错误,它会惨遭失败。 原因是正在考虑将模板中添加的独立订阅作为新资源并尝试创建它。除了手动删除该订阅外,我没有找到解决此问题的好方法,这在生产环境中不是一个好习惯。

A caveat though, is that if you already created a topic with that subscription and are now trying to add the attribute, it'd fail miserably with Invalid Parameter error. The cause is it's considering the standalone Subscription added in the template as a new resource and trying to create it. I haven't found a good way around this other than deleting that subscription manually, which is not good practice in production environment.

我的解决方法是将其分为2个步骤。首先,从主题中删除属性订阅,然后添加订阅资源。然后,向订阅资源添加新属性。

My solution around this is separating it into 2 steps. First, remove the property subscription from the topic and add a Subscription resource. Then, add new attributes to the subscription resource.

首先:

{
    "AcceptedTopic": {
        "Type": "AWS::SNS::Topic",
        "Properties": {
            "DisplayName": {
                "Fn::Join": ["", ["Accepted-", {"Ref": "Env"}]]
            },
            "TopicName": {
                "Fn::Join": ["", ["Accepted-", {"Ref": "Env"}]]
            }
        }
    }
    "AcceptedTopicSubscription": {
        "TopicArn": { "Ref": "AcceptedTopic" },
        "Endpoint": {
            "Fn::GetAtt": ["SomeQueue", "Arn"]
        },
        "Protocol": "Sqs"
    }
}

然后:

{
    ...
    "AcceptedTopicSubscription": {
        "TopicArn": { "Ref": "AcceptedTopic" },
        "Endpoint": {
            "Fn::GetAtt": ["SomeQueue", "Arn"]
        },
        "Protocol": "Sqs",
        "RawMessageDelivery": "true"
    }
}

这篇关于如何使用AWS CloudFormation为SNS订阅指定“原始消息传递”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆