Understanding AWS Lambda Versions and Aliases

2 Minutes Serverless Reads — #05

Muhammad Abutahir
Towards AWS

--

Photo by Maarten Deckers on Unsplash

AWS Lambda is the essence of Serverless. It has a lot of optimization features available out of the box. Be it code optimizations or deployment features, AWS Lambda has it all!

One feature that has helped developers achieve seamless deployments is the Lambda Alias and Versions.

What are Lambda Versions?

A lambda version is a snapshot of your Lambda function. When you create a new lambda function, it is named as $LATEST . This is the unpublished version of your lambda function. When you publish a lambda function, A numerical alias is given to your published lambda function. The $LATEST is still present with the newly made changes. When you make more changes and publish, new versions get created. Thus, leading to a fair management of the deployments of the lambda functions.

Lambda versions are immutable, which means that once a version is published, it cannot be changed or modified. A lambda function version encapsulates the following:

  • The code and its related dependencies.
  • The runtime of the lambda function.
  • The environment variables and all related settings.
  • A unique ARN for every new version.

What is Lambda Alias?

A lambda alias at its simplest is a pointer to the lambda function’s version. We can use aliases to point to any lambda version you specify. These aliases can be used to invoke the specific version. We can also specify weights for the aliases. For example: Assume we have created an alias and named it as Prod and we have two lambda functions A and B . We can now direct a sample amount of traffic to the B version we need to test out. Once the results match our expectations, we can move complete traffic to this B which can now serve the production environment. Thus we can safely deprecate the older version.

Advantages

Versioning offers good stability and traceability, every version has a unique identifier and this is very helpful in tracing the state of the function over time. Another major and well-known advantage is quick rollbacks. It’s very easy to quickly roll back to the previous version if there are any issues by simply pointing the alias to the previous version. This helps to reduce any disruptions to the users very easily.

Conclusion

The combination of lambda versions and aliases majorly helps us achieve blue-green deployments. For a detailed understanding of how to perform the blue-green deployments, please refer to my article - Blue-Green Deployments With AWS Lambda. This article gives a brief introduction to the blue-green deployment strategy.

Happy Versioning!

--

--

I am a Backend Engineer primarily focusing on Serverless technologies, Python and NodeJS. Feel free to connect with me: https://www.linkedin.com/in/abu-tahir/