title: AWS Cloudformation Template Deployment Failure due to SNS Topic Subscription already exists with different attributes
body: <p>I have AWS CloudFormation template that defines:</p>
  <ul>
  <li>A topic</li>
  <li>A queue</li>
  <li>A subscription of the queue to the SNS topic</li>
  </ul>
  <p>The topic has 3 subscribers, all of them are AWS SQS queue.</p>
  <p>Here are the excerpt of serverless.yml:</p>
  <pre><code>provider:
    stage: ${opt:stage, 'staging'}
  custom:
    prefix: ${self:provider.stage}-email
    resources:
        deletionPolicy:
          local: Delete
          staging: Delete
          prod: Retain
  
  EmailSnsTopic:
        DeletionPolicy: ${self:custom.resources.sns.deletionPolicy.${self:provider.stage}}
        Type: AWS::SNS::Topic
        Properties:
          TopicName: ${self:custom.prefix}-EmailSnsTopic
          DisplayName: &quot;EmailSnsTopic Data ingestion pipeline&quot;
  </code></pre>
  <p>The SQS Queue, and its subscription to the topic.</p>
  <pre><code>EmailQueue:
    Type: AWS::SQS::Queue
    DeletionPolicy: ${self:custom.resources.sqs.deletionPolicy.${self:provider.stage}}
    Properties:
      QueueName: ${self:custom.sqs.EmailQueueName}
      MessageRetentionPeriod: 1209600
      VisibilityTimeout: ${self:custom.sqs.MESSAGE_VISIBILITY_TIMEOUT}
      ReceiveMessageWaitTimeSeconds: ${self:custom.sqs.RECEIVE_MESSAGE_WAIT_TIME}
      RedrivePolicy:
        deadLetterTargetArn: 
          Fn::GetAtt:
          - EmailDLQ
          - Arn
        maxReceiveCount: ${self:custom.sqs.MAX_RETRY}
  
  EmailSnsSubscription:
        UpdateReplacePolicy: Retain
        DeletionPolicy: ${self:custom.resources.sns.deletionPolicy.${self:provider.stage}}
        Type: AWS::SNS::Subscription
        Properties:
          Protocol: sqs
          Endpoint:
            Fn::GetAtt:
              - EmailQueue
              - Arn
          FilterPolicy:
            action: [{anything-but: sendSmsOnly}]
          RawMessageDelivery: false
          TopicArn: arn:aws:sns:${self:provider.region}:${self.account}:${self:provider.stage}-EmailSnsTopic
  </code></pre>
  <p>I have 2 environments: production and staging. The deployment at staging environment works well, without any error. But the deployment at production environment generates this error message:</p>
  <blockquote>
  <p>Serverless: Checking Stack update progress...
  CloudFormation - UPDATE_IN_PROGRESS - AWS::CloudFormation::Stack - email-prod
  CloudFormation - CREATE_IN_PROGRESS - AWS::SNS::Subscription - EmailSnsSubscription</p>
  <p>CloudFormation - CREATE_FAILED - AWS::SNS::Subscription - EmailSnsSubscription
  ...
  ...
  CloudFormation - UPDATE_ROLLBACK_COMPLETE - AWS::CloudFormation::Stack - email-prod
  Serverless: Operation failed!</p>
  <p>Serverless Error ---------------------------------------</p>
  <p>An error occurred: EmailSnsSubscription - Invalid parameter: Attributes Reason: Subscription already exists with different attributes (Service: AmazonSNS; Status Code: 400; Error Code: InvalidParameter; Request ID: xxx-xxxx-xxxxx; Proxy: null).</p>
  </blockquote>
  <p>I am very confused because it works at staging environment, but not at production environment.</p>
  <p>What are possible root causes of the problem?</p>