In this article, we will discuss “How to Manage AWS Lambda Versioning and Aliases”. The use of AWS Lambda versioning and Aliases are the safest way to manage and deploy the Lambda functions. We can split our production and testing environment easily. No one can apply any kind of change in the published version, because of this our production published version is completely safe for an unwanted or accidental change. I will try to explain both ways such as GUI and Command-Line in this article.
Table of Contents
Lambda Versions
Each of the Lambda versions has a unique ARN. For more details, check the official documentation for Lambda Versions. The function ARN will have a format such as:
arn:aws:lambda:us-east-1:xxxxxxxxxxxx:function:test_func:1
“xxxxxxxxxxxx” stands for the AWS account id, and test_func is a Lambda function name. The number 1 at the end of the ARN indicates the version. Also, possible to refer to a function’s latest version:
arn:aws:lambda:us-east-1:xxxxxxxxxxxx:function:test_func:$LATEST
Consumers relying on the latest version will automatically use a new version once promoted to $LATEST. When the Lambda version is omitted, the ARN is said to be unqualified:
arn:aws:lambda:us-east-1:xxxxxxxxxxxx:function:test_func
For teams that decide not to use the AWS Lambda versioning system, the qualified or unqualified versions won’t make any difference.
Publish Lambda Version using CLI
Using the AWS command-line interface, a version is published with the following command:
aws lambda publish-version --function-name test_func
Publish Lambda Version using GUI (AWS Management Console)
Open AWS Management Console and go to Lambda dashboard. Select the Lambda function and click on the versions tab as given below:
Click on the “Publish new version” button and add the version description. It’s an optional requirement but I recommend adding a short description of that version.
Our function version “1” is published now.
Lambda Aliases
Similar to Lambda versions, aliases has a unique ARN. Each of the Aliases represents a specific version. We have to attach the version to the Lambda Aliases. For more details, check the official documentation for Lambda Aliases.
For example, a Lambda function has a PROD alias. The development team deploys a new version after the testing and then points the PROD alias to the new stable version. The function ARN will have a format such as:
arn:aws:lambda:us-east-1:xxxxxxxxxxxx:function:test_func:Prod
So when we publish a new version then we have to link that version with the alias.
Create Lambda Alias using CLI
Using the AWS command-line interface, an alias is created with the following command:
aws lambda create-alias --function-name test_func --function-version version 1 --name hello-alias --description "This is a 'Hello World' Alias"
Update Lambda Alias using CLI
Updating the version to which an alias points (to version 2, for example)
aws lambda update-alias --function-name test_func --name hello-alias --function-version 2
Create Lambda Alias using GUI (AWS Management Console)
Open AWS Management Console and go to Lambda dashboard. Select the Lambda function and click on the aliases tab as given below:
Click on the “Create alias” button and add the name and description. Again, description is an optional requirement but I recommend adding a short description of that alias. After that select the version from the given dropdown. This means your alias is linked with that version.
Our function alias “Prod” is created successfully.
Conclusion
In this article, we are discussing “How to Manage AWS Lambda Versioning and Aliases”. I’m trying to explain to you about Lambda versioning and aliases, hope you like this article. Note that AWS provides us the easiest way to apply the configuration to specific versions and aliases such as permission, triggers or etc. Please feel free to add comments if any queries or suggestions.
Keep learning & stay safe 😉
You may like:
How to Setup AWS Pinpoint (Part 1)
Create AWS IAM User with Programmatic Access
How to Upload File to AWS S3 Bucket Laravel
Basic Understanding on AWS Lambda
If you like our content, please consider buying us a coffee.
Thank you for your support!
Buy Me a Coffee