Howto specify 'Raw Message Delivery' for an SNS subscription using AWS CloudFormation?

↘锁芯ラ 提交于 2019-12-01 18:08:26

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.

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.

First:

{
    "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"
    }
}

Then:

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

As of this writing, AWS CloudFormation doesn't support that natively. As an alternate, you can create a Lambda-backed custom resource to get around this limitation and set that attribute using set-subscription-attributes instead. Here are some helpful resources to help accomplish that:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!