I would like to export my Lambda ARN that I created using the serverless framework, as I need to use this ARN in other CF template
I defined Outputs and Export in my serverless.yml file.
resources:
Outputs:
ServiceLambdaFunctionQualifiedArn:
Export:
Name: MyServiceARN
It's working fine.
However, the export contains the lambda version ARN (i.e arn:aws:lambda:region:12345:function:servicename:2).
This is causing issue as this ARN is used by other CF thus cannot be updated.
"Export MyServiceArn cannot be updated as it is in use by xyz"
Is there a way to get the ARN without the version number ?
Thanks for your help.
You can use the intrinsic functions, specifically Fn::GetAtt to get the lambda function's arn.
To export a stack's output value, use the Export field in the Output section of the stack's template. To import those values, use the Fn::ImportValue function in the template for the other stacks. For a walkthrough and sample templates, see Walkthrough: Refer to resource outputs in another AWS CloudFormation stack.
When editing a lambda function, you can go Actions > Export Function > Download deployment package. This downloads a . zip file of the function. This duplicates the code and npm modules etc...
Try
resources:
Outputs:
ServiceLambdaFunctionQualifiedArn:
Export:
Name: MyServiceARN
Value:
Fn::GetAtt: ServiceLambdaFunction.Arn
Update 07-2020
This question is still valid, and the accepted answer did not work for me with serverless 1.74.1. My use case was to export a custom authorizer lambda (as a separate service) to other services.
Here is what worked for me:
resources:
Outputs:
ServiceLambdaFunctionQualifiedArn:
Export:
Name: MyServiceARN
You don't need a reference to value, the arn should be exported with just the name.
Then to use the Export in another service:
authorizer:
name: MyServiceARN
arn:
Fn::ImportValue: MyServiceARN
The "name" added to this ended up being required for the custom authorizer use case.
This has worked for me:
Export in first serverless stack with a unique export name <stack>-<stage>-TransformDataLambdaArn
:
service: first-service
provider:
name: aws
runtime: nodejs12.x
region: eu-west-1
stage: ${opt:stage, 'dev'}
functions:
myLambda:
handler: src/handlers/myLambda.handle
resources:
Outputs:
MyLambdaFunctionArn:
Description: 'ARN will be imported by other stacks'
Value: !GetAtt MyLambdaFunction.Arn
Export:
Name: ${self:service}-${self:provider.stage}-MyLambdaArn
And import in the second stack with the same stage like this:
Fn::ImportValue: first-service-${self:custom.stage}-MyLambdaArn
In short:
!GetAtt MyCreatedResource.Arn
E.g.
Outputs:
FluentBitVerifyRole:
Description: ARN of the verification role
Value: !GetAtt FluentBitVerifyRole.Arn
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With