Export the Lambda ARN
UPDATE
In response to the first comment, I'd like to give some context to this answer: the author asked how to export the ARN without the version number?
The actual problem lies in the Key that was used to export the function ARN: ServiceLambdaFunctionQualifiedArn
resources:
Outputs:
ServiceLambdaFunctionQualifiedArn: # <- CloudFormation Key
Export:
Name: MyServiceARN
The Serverless Framework, by default, exports each Lambda function with their Qualified Function ARN (i.e., ARN plus version suffix) as CloudFormation Stack Output. That means, the Lambda function hello will be exported as HelloLambdaFunctionQualifiedArn, even if you don't define any outputs in the resources section. Just check the CloudFormation Stack output of a deployed Serverless service:
That means, Serverless will overwrite your output declaration ServiceLambdaFunctionQualifiedArn with their own declaration during deployment. By the way, that is also the reason that it was working even though no actual Value was specified.
In order to export the ARN without version number, you must manually declare an additional output with a different Key, for example HelloLambdaFunctionArn or ServiceLambdaFunctionArn (remove Qualified from the string), and reference the ARN as Value:
resources:
Outputs:
ServiceLambdaFunctionArn: # <- CloudFormation Key
Value: !GetAtt ServiceLambdaFunction.Arn # <- CloudFormation Value
Export:
Name: ${self:service}-${self:provider.stage}-MyServiceARN
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
Try
resources:
Outputs:
ServiceLambdaFunctionQualifiedArn:
Export:
Name: MyServiceARN
Value:
Fn::GetAtt: ServiceLambdaFunction.Arn