How to export the qualified ARN of lambda functions created in serverless.yml


#1

Hi,

I’d like to be able to export the qualified arn of lambda functions that I have defined in the serverless.yml file. In other words, the lambda arn plus the function version.

This is so that I can reference it as a cross-script reference in separate CloudFormation files.

I am able to export the unqualified arn using the name of my function plus ‘LambdaFunction’ as shown below:

 MyFunctionUnqualifiedArn:
      Value:
        'Fn::GetAtt': [ MyFunctionLambdaFunction, Arn ]
      Export:
        Name: 'my-function-arn'

But I’d really like to include the function version, if possible.

Thanks


#2

Serverless will already do an Output of your MyFunctionLambdaFunction qualified arn using this resource name “MyFunctionLambdaFunctionQualifiedArn” in the cloudformation template that it generates, so you can try adding this to your serverless.yml under

resources:
  Resources: ...
  Outputs:
      MyFunctionLambdaFunctionQualifiedArn:
        Export:
          Name: MyFunctionLambdaQualifiedArn

This will just add the Export property to the Outputs: in the cfn template, that is generated in the “.serverless” folder. Make sure the resource name matches the one that was generated in the cfn template. Use command serverless package to populate the .serverless folder if you don’t have one.