I am using the Serverless Framework to create a lambda function and would like to be able to cross-reference its Arn and name in other parts of serverless.yml.
I'm surprised how difficult I'm finding this as !GetAtt and !Ref do not seem to work as I would expect if the lambda was created via vanilla CloudFormation. (AWS::Lambda::Function returns Ref and Fn::GetAtt which would make this easy!)
I have found a few posts, that allude to solutions, but nothing that states in plain English how to achieve this.
SETUP
serverless.yml
...
functions:
- ${file(functions/sendEmail.yml)}
...
sendEmail.yml
sendEmail:
handler: lambda-functions/send-email.handler
...
ATTEMPTS TO REFERENCE
Arn
In another part of the template I have attempted:
...
LambdaFunctionArn: !GetAtt sendEmail.Arn
but, when I deploy, I get:
Error: The CloudFormation template is invalid: Template error: instance of Fn::GetAtt references undefined resource sendEmail
I notice that the final CloudFormation template has converted sendEmail to sendEmailLambdaFunction, so I then tried:
LambdaFunctionArn: !GetAtt sendEmailLambdaFunction.Arn
but received a similar error.
Name
I also would like to be able to reference the name, but sadly
!Ref sendEmail
causes the error:
Error: The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [sendEmail] in the Resources block of the template
Any assistance with regards to precise changes I need to make, in order to achieve grabbing the lambda's Arn and name, would be greatly appreciated!
Thanks in advance! I