使用SNSEvent配置Lambda *,并使用协议创建订阅:lambda仅产生一个Subscription,但是哪个?

问题描述

如果您使用SNSEvent配置Lambda,则会创建一个预订。

如果您使用Protocol: lambda配置订阅,这也会创建一个订阅

同时配置两者(具有完全相同的端点)时,您只会获得一个订阅。两者都合并了吗,一个覆盖了另一个,究竟发生了什么?

我要更好地了解CloudFormation。

例如:

# ReceivedRequestSNS Role
   ReceivedRequestsSNS:
     Type: AWS::SNS::Topic
     Properties:
       TopicName: !Sub
         - ${StackName}-ReceivedRequests-${Stage}
         - StackName: !Ref AWS::StackName
           Stage: !Ref Stage 

   ReceivedRequestsToLambdaSuscription:
     Type: AWS::SNS::Subscription
     Properties:
       Protocol: lambda
       Endpoint: !Sub
         - ${LambdaArn}:live
         - { LambdaArn: !GetAtt TrainingNotificationsRequestsHandler.Arn }
       RedrivePolicy:
         deadLetterTargetArn : !GetAtt ReceivedRequestsSNSDLQ.Arn
       TopicArn: !Ref ReceivedRequestsSNS

   TrainingNotificationsRequestsHandler:
     Type: AWS::Serverless::Function
     Properties:
       Handler: 'com.test.handlers.RequestsHandler::handleRequest'
       Runtime: java8
       Events:
         SNSEvent:
           Type: SNS 
           Properties:
             Topic: !Ref ReceivedRequestsSNS

解决方法

SAM Documentation指出:

设置此事件类型后,SAM会生成AWS :: SNS :: Subscription资源

我将使用SAM SNS事件源或“原始” AWS:SNS::Subscription,但不能同时使用两者。两者都指定时,任何行为似乎都没有记录,因此不应依赖。