Error in SNS configuration for pre-existing SNS topic?

Hi,

Not sure if this is an error … but the behavior is surprising, so I thought I’d report it.

  handleSesSuppressions:
    handler: handleSesSuppressions.handler
    events:
      - sns:
          arn: ${{self:resources.Outputs.BouncesSnsTopic.Value}}
          topicName: ${{file(./commonResources/serverless.yml):provider.environment.BouncesSnsTopic}}
      - sns:
          arn: ${{self:resources.Outputs.ComplaintsSnsTopic.Value}}
          topicName: ${{file(./commonResources/serverless.yml):provider.environment.ComplaintsSnsTopic}}

This deploys. As seen in cloudformation-template-update-stack.json:

    "HandleSesSuppressionsSnsSubscriptionIrhsesbounces": {
      "Type": "AWS::SNS::Subscription",
      "Properties": {
        "TopicArn": {
          "Fn::Sub": "arn:aws:sns:${AWS::Region}:${AWS::AccountId}:irh-ses-bounces"
        },
        "Protocol": "lambda",
        "Endpoint": {
          "Fn::GetAtt": [
            "HandleSesSuppressionsLambdaFunction",
            "Arn"
          ]
        }
      }
    },

However, this does not deploy:

  handleSesSuppressions:
    handler: handleSesSuppressions.handler
    events:
      - sns: ${{self:resources.Outputs.BouncesSnsTopic.Value}}
      - sns:
          arn: ${{self:resources.Outputs.ComplaintsSnsTopic.Value}}
          topicName: ${{file(./commonResources/serverless.yml):provider.environment.ComplaintsSnsTopic}}

Produces this error message:

     Missing or invalid topicName property for sns event
     in function "handleSesSuppressions" The correct syntax
     is: sns: topic-name-or-arn OR an object with  arn and
     topicName OR topicName and displayName. Please check
     the docs for more info.

It seems like I am meeting the requirements for using a pre-existing SNS topic by not including the Topic Name:


Which seems redundant, since it’s included in the ARN:

    BouncesSnsTopic:
      Description: SNS topic to receive SES bounces.
      Value:
        Fn::Sub: arn:aws:sns:${AWS::Region}:${AWS::AccountId}:${{file(./commonResources/serverless.yml):provider.environment.BouncesSnsTopic}}

Am I reading the documentation incorrectly?

Thanks in advance!

The docs say that using:

- sns: ${{self:resources.Outputs.BouncesSnsTopic.Value}}

will only work if ${{self:resources.Outputs.BouncesSnsTopic.Value}} resolves to a value starting with arn:

Read the second half of the docs covering the usage with intrinsic CloudFormation functions. The topicName is required and the topciArn must contain the value given in topicName.

Ah, gotcha, thanks for explaining. The reason it threw both me and my fellow developers is because similar approaches have worked in other places, I think - in other words, replacing a literal string starting with “arn:” could be replace with a “Fn::Sub: arn:xxx:” etc. string. For example, it works in the “arn:” field but not the “sns:” field. So I think you could imagine our confusion that wasn’t resolved by the documentation of that page.

Thanks!