通过 Cloudformation 配置时,SNS 主题不发送管道事件更改电子邮件

SNS Topic is not sending the pipeline event change emails when configured through Cloudformation

我正在创建一个 cloudwatch event,它将在我的 code pipeline 中发生状态更改并分配给 SNS topic 时触发。我正在通过 Cloudformation Stack 进行上述所有配置。下面是我的堆栈模板

{
    "Description": "Triggering CodePipeline notifications.",
    "AWSTemplateFormatVersion": "2010-09-09",
    "Parameters": {
        "EmailAddress": {
            "Description": "Email Address",
            "Type": "String"
        }
    },
    "Resources": {
        "EventRule": {
            "Type": "AWS::Events::Rule",
            "Properties": {
                "Description": "EventRule",
                "EventPattern": {
                    "source": [
                        "aws.codepipeline"
                    ],
                    "detail-type": [
                        "CodePipeline Pipeline Execution State Change"
                    ],
                    "detail": {
                        "state": [
                            "FAILED"
                        ],
                        "pipeline": [
                           "mypipelinename"
                        ]
                    }
                },
                "State": "ENABLED",
                "Targets": [
                    {
                        "Arn": {
                            "Ref": "MySNSTopic"
                        },
                        "Id": "PipelineNotificationTopic",
                        "InputTransformer": {
                            "InputTemplate": "\"The Pipeline <pipeline> has failed.\" ",
                            "InputPathsMap": {
                                "pipeline": "$.detail.pipeline"
                            }
                        }
                    }
                ]
            }
        },
        "MySNSTopic": {
            "Type": "AWS::SNS::Topic",
            "Properties": {
             "TopicName": "Huaaa",
                "Subscription": [
                    {
                        "Endpoint": {
                            "Ref": "EmailAddress"
                        },
                        "Protocol": "email"
                    }
                ]
            }
        }
    }
}

这正在创建所有必要的资源,如 cloudwatch 事件和 SNS 订阅,并向我的电子邮件地址发送确认通知。但是当 mypipeline 中有 state change 时,这不会触发任何电子邮件通知。

但是当我创建一个新的 SNSTopic 并使用 aws console 创建一个 subscription 并将其附加到由 cloudformation stack 创建的 cloudwatch 事件作为目标时工作正常。我可以在有变化时收到通知。

我的模板中是否缺少任何内容?

谢谢 感谢任何帮助

您未设置允许发布的AWS::SNS::TopicPolicy

例如(写成.yml)

MySNSTopicPolicy:
  Type: AWS::SNS::TopicPolicy
  Properties:
    Topics:
      - !Ref MySNSTopic
    PolicyDocument:
      Version: 2012-10-17
      Statement:
        - Effect: Allow
          Principal:
            AWS: '*'
          Action: sns:Publish
          Resource: !Ref MySNSTopic