So as per the AWS documentaion
Instead of using Amazon Resource Names (ARNs) for Lambda function in event source mappings, you can use an alias ARN. This approach means that you don't need to update your event source mappings when you promote a new version or roll back to a previous version.
I have AWS lambda function pets
and i have created 2 aliases dev
and prod
pointing to different versions of lambda function.
Then in API Gateway i am using this lambda function in Integration Request
. I have two stages of API, development
and production
. I want development
API stage point to dev
Lambda alias ARN and production
needs to point to prod
alias.
When i select lambda function as Integration Type
then drop down list shows whatever display name i have given earlier while creating lambda function..
I am not finding any stage specific configuration for lambda function. Based on my research on SO i have to follow these steps to deploy development
stage pointing to dev
alias
1> Go to Integration Request
2> Select Lambda function and change it to pets:dev
3> Deploy to development
stage
Follow the same steps for production
by changing Lambda function to pets:prod
before deployment.
This is going to be maintenance nightmare as our lambda function grows. Is there any easier way to do it?
Managing aliases with the Lambda API To create an alias using the AWS Command Line Interface (AWS CLI), use the create-alias command. To change an alias to point a new version of the function, use the update-alias command. To delete an alias, use the delete-alias command.
I found it
https://aws.amazon.com/blogs/compute/using-api-gateway-stage-variables-to-manage-lambda-functions/
Here are the steps I followed:
dev
pointing to $latest
version and prod
pointing a
particular version you want to use in prodpets:${stageVariables.lambdaAlias}
where pets
is my function name and lambdaAlias
is the stage variable that we will have to add in each API stagedevelopment
and production
lambdaAlias
with value dev
and prod
respectively. The stage variable value must match with lambda function's aliasNow we don't have to keep changing lambda alias name for each API deployment
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