Pass email address list to SNS subscription endpoint

Viewed 290

Is it possible to pass a list of email addresses as the endpoint for an SNS subscription?

I've got something like this

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Resources" : {
      "EmailSNSTopic": {
        "Type" : "AWS::SNS::Topic",
        "Properties" : {
          "DisplayName" : "${display_name}"
        }
      },
      "MySubscription": {
        "Type": "AWS::SNS::Subscription",
        "Properties": {
          "TopicArn" : { "Ref" : "EmailSNSTopic" },
          "Endpoint" : "foo@foo.com"
          "Protocol" : "email"
        }
      }
    },
      "Outputs" : {
        "ARN" : {
          "Description" : "Email SNS Topic ARN",
          "Value" : { "Ref" : "EmailSNSTopic" }
        }
      }
}

But what I'd like to do is pass a number of email addresses instead of just one.

2 Answers

As per the documentation

Endpoint should be a string

Cloudformation doesn't allow you to pass a list.

You dont want to have a custom resource as well.

There is one more way Running bash commands in AWS CloudFormation templates

You just run awscli command like below

    Resources:
    Command:
        Type: 'AWSUtility::CloudFormation::CommandRunner'
        Properties:
        Command: aws s3 ls > /command-output.txt
        Role: String
        LogGroup: String #Optional
        SubnetId: String #Optional
        SecurityGroupId: String #Optional
        KeyId: String #Optional

I don’t thing it is possible using native syntax.

You might want to try aws cloud formation custom resource and pass list to lambda for execution one by one.

Related