I have a custom authorizer in AWS (a serverless project as well, inside the same AWS account and environment), I am trying to reference it in my serverless project as described in the documentation.
I am having trouble referencing the authorizer using ARN, can someone please show me an example of referencing a Lambda function using ARN.
"If the Authorizer function does not exist in your service but exists in AWS, you can provide the ARN of the Lambda function instead of the function name, as shown in the following example:
@pgali Do you know the ARN of your authorizer function? If you need to find it, you can navigate to your function in the AWS Lambda console. The ARN will be listed at the top – it will look something like arn:aws:lambda:us-east-1:786336611111:function:custom-authorizer.
To use it as the authorizer in your Serverless service, paste the ARN into your service:
That’s how I got it to work for now, but that wouldn’t work in an automated deployment environment. I want to be able to reference the ARN programatically and do not want to be tied up using static ARN names in serverless yaml file
If you don’t want that, you could manage the Authorizer function in a different CloudFormation stack and have the Lambda ARN as an output. Then you could reference the ARN programmatically using the CloudFormation Output variable syntax:
Any chance you could help me with a working sample of exporting an ARN that can be referenced in another cloud stack? I used to be able to do that in the past, but having difficultly this time
Are you managing your authorizer Lambda function with Serverless? If so, go to that service directory and run sls info -v. In the output, it prints out a lot of information about your service. You need to look for two things: stack (in the Service Information section), and <FunctionName>LambdaFunctionQualifiedArn in the Stack Outputs section.
In your other Serverless service, you can refer to this using ${cf:<stack>.<LambdaOutputKey>}.
For example:
Service Information
service: test-service
stage: prod
region: us-west-2
stack: test-service-prod
api keys:
None
functions:
hello: test-service-prod-track
Stack Outputs
HelloLambdaFunctionQualifiedArn: arn:aws:lambda:us-west-2:111110002222:function:test-service-prod-hello:1
ServerlessDeploymentBucketName: test-service-prod-serverlessdeploymentbucket-8qhsgorht4bc
In this one, my stack is test-service-prod. The output key for my function is HelloLambdaFunctionQualifiedArn. So to refer to it in my other serverless.yml:
An interesting read, however, my authorizer is a Cognito user pool, I’ve already got one API Authorizer setup, so I’d like to refer to it in each of my endpoints (from multiple services).
It is possible to x-reference a stack. The problem is the output CF parameter includes the version number of the authoriser in the arn, so you could use the yaml Join function to construct the arn given the you know the actual name of the lambda itself. The arn is in the form: