12

考虑 serverless.yml 文件上的这个 lambda 函数:

functions:
  s3toEc2Lambda:
    handler: s3toec2lambda.S3toEc2Lambda
    name: "${self:service}-s3toEc2Lambda"
    role: S3toEc2LambdaRole

并考虑在资源部分创建的此 SNS:有人知道如何从 lambda 函数 s3toEc2Lambda 通知 Sns ARN 端点吗?

resources:
  Resources:
    WordpressFrontEndSnsS3toEc2:
      Type: AWS::SNS::Topic
      Properties:
        TopicName: "wordpress-front-end-s3-ec2"

    WordpressFrontEndSnsS3toEc2Lambda:
      Type: AWS::SNS::Subscription
      Properties:
        Endpoint: { "Fn::GetAtt": ["s3toEc2Lambda", "Arn" ] }                    <------ HERE    <------
        #Endpoint: ${self:functions.s3toEc2Lambda}                               <------ OR HERE <------
        #Endpoint: { "Fn::GetAtt": ["${self:functions.s3toEc2Lambda}", "Arn" ] } <------ OR HERE <------
        Protocol: lambda
        TopicArn: !Ref 'WordpressFrontEndSnsS3toEc2'

对我来说,总是出现这样的错误消息:“模板错误:Fn::GetAtt 的实例引用未定义的资源 s3toEc2Lambda”

谢谢你 !

4

1 回答 1

13

无服务器创建的 CloudFormation 资源具有已知格式。对于 lambda 函数,这是:

{normalizedFunctionName}LambdaFunction

因此,您应该能够使用以下方法引用您的函数:

"Fn::GetAtt": [ S3toEc2LambdaLambdaFunction, Arn ]

更多关于这个的例子是here

于 2020-05-24T21:55:24.233 回答