7
votes

Considering this lambda function on a serverless.yml file:

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

And considering this SNS created on resources section: Does someone knows how to inform the Sns ARN Endpoint from the lambda function s3toEc2Lambda ?

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'

For me always appear a error message like this: "Template error: instance of Fn::GetAtt references undefined resource s3toEc2Lambda"

Thank You !

1

1 Answers

7
votes

CloudFormation resources created by serverless have known format. For lambda function this is:

{normalizedFunctionName}LambdaFunction

Thus you should be able to reference your function using the following:

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

More example about this are here