简体   繁体   中英

SQS subscribing to SNS: How to specify multiple TopicArns in CloudFormation?

A different team has created several SNS topics to work around the SNS quotas. The ARNs are

arn:aws:sns:us-west-1:xxxx:SomeTopic.fifo
arn:aws:sns:us-west-1:xxxx:SomeTopic1.fifo
arn:aws:sns:us-west-1:xxxx:SomeTopic2.fifo
...
arn:aws:sns:us-west-1:xxxx:SomeTopicN.fifo

I am trying to subscribe an SQS to these topics. My CloudFormation looks like below, with lots of duplication:

{
    "AWSTemplateFormatVersion" : "2010-09-09",
    "Parameters"               : {
        "SomeTopicArn" : {
            "Type" : "String",
            "Default" : "arn:aws:sns:us-west-1:xxxx:SomeTopic.fifo"
        },
        "SomeTopicArn1" : {
            "Type" : "String",
            "Default" : "arn:aws:sns:us-west-1:xxxx:SomeTopic1.fifo"
        }
    },
    "Resources"                : {
        "SomeQueue" : {
            "Type" : "AWS::SQS::Queue",
            "Properties" : {
                "QueueName" : "SomeQueue.fifo",
                "FifoQueue"                     : "true"
            }
        },
        "SubscribeSomeQueueSqsToSomeTopic" : {
            "Type" : "AWS::SNS::Subscription",
            "Properties" : {
                "Protocol" : "sqs",
                "Endpoint" : {
                    "Fn::GetAtt" : [
                        "SomeQueue",
                        "Arn"
                    ]
                },
                "TopicArn" : {
                    "Ref" : "SomeTopicArn"
                }
            }
        },
        "SubscribeSomeQueueSqsToSomeTopic1" : {
          "Type" : "AWS::SNS::Subscription",
          "Properties" : {
            "Protocol" : "sqs",
            "Endpoint" : {
              "Fn::GetAtt" : [
                "SomeQueue",
                "Arn"
              ]
            },
            "TopicArn" : {
              "Ref" : "SomeTopicArn1"
            }
          }
        }
    }
}

How can I specify multiple TopicArns in one "AWS::SNS::Subscription" to avoid duplication.

I tried using wild cards in the parameters

"Parameters"               : {
        "SomeTopicArn" : {
            "Type" : "String",
            "Default" : "arn:aws:sns:us-west-1:xxxx:SomeTopic*.fifo"
        },

but it errors out as invalid ARN.

There is no such way unless you are going to develop your own custom resource or template macro for that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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