Understanding AWS Lambda functions, versions, and aliases

Share the post:
AWS Lambda is a powerful service that allows you to run code without provisioning or managing servers. Lambda functions can be incredibly flexible and allow you to run them in various environments, from development to production. To make managing these functions smoother, AWS provides versions and aliases. Let's dive into what these are and how they can help you manage different environments effectively.

What is AWS Lambda?

An AWS Lambda function is essentially a small, single-purpose piece of code that you write and upload to AWS. It is designed to be invoked in response to specific events, like changes in data, HTTP requests, or even scheduled tasks. Once invoked, the code inside the Lambda function is run automatically, thus creating nearly endless possibilities for automation.

Here’s an example of something that can be automated using AWS Lambda: when an image is uploaded to an AWS S3 storage bucket, a Lambda function is triggered that processes the image and creates resized versions in different resolutions. This ensures that images are appropriately sized for various uses, such as thumbnails or high-resolution displays.

Lambda versions

Every time you update your Lambda function code, AWS creates a new version of that function. A version is a snapshot of your Lambda function code and its configuration at a specific point in time. Each version is immutable, which means once it’s published, it cannot be changed. This immutability ensures that your production environment is stable and predictable.

  • Versioning: When you publish a version of your Lambda function, AWS assigns it a unique version number. For example, the initial version of your function might be 1, and subsequent updates would create versions 2, 3, and so on.
  • $LATEST: Note that the code for AWS Lambda that you see by default, is for the version called $LATEST.

Lambda aliases

Aliases are pointers to specific versions of a Lambda function. They provide a way to manage and switch between versions of your function easily without modifying the code itself. 

Think of aliases as domain names pointing to specific IP addresses. Just as you can change an IP address behind a domain name, you can change the version number an alias points to. If you invoke an alias of a Lambda function, whatever version of that function the alias is pointing to, will be invoked. Versions and aliases are very useful features for managing different environments inside the same AWS Lambda function.

Managing environments using versions and aliases of AWS Lambda

This is how you can combine versions and aliases to construct a robust environment for your AWS Lambda function. Let’s say you have deployed your code on your Lambda function, and also published a number version, say version 1.

  • Creating aliases: create an alias dev pointing to version $LATEST, and test and prod aliases both pointing to version 1.

  • Updating aliases: let’s say you change your code and redeploy it to your Lambda function. You’ve done a few checks and think the new code is ready for testing. You can publish another numbered version, 2. Update your test alias to point to version 2. Once testing is completed, you can have your prod alias point to version 2 as well.

This approach ensures a smooth transition with minimal disruption. If your Lambda functions are designed to be invoked using their aliases, none of the references in your code needs to change during testing or production deployment.
 
Other benefits of versions and aliases in management of environments include:
  • Quick rollbacks: If a newly deployed version in production has issues, you can quickly rollback by updating the prod alias to point back to a previous stable version.

  • Version control: With versions, you can always track which version of the code is running in which environment. This makes debugging easier and ensures consistency across deployments.

  • Gradual rollouts: You can use aliases to implement blue/green deployments or canary releases by gradually shifting traffic between different versions. For example, direct 10% of traffic to the new version while keeping 90% on the old version, and then fully roll out once the new version is validated.

Lambda versions and aliases are essential tools for managing your Lambda functions across different environments. They allow you to isolate development work, ensure stable production deployments, and quickly roll back if issues arise. By using these features strategically, you can enhance your deployment workflows, reduce risks, and improve the overall reliability of your serverless applications.

Share the post:

Related posts

Databricks to Excel using Power Query

How to get data from Databricks in Excel using Power Query

Databricks is a unified data engineering platform renowned for it’s ability to process large datasets. Excel remains the tool of choice for analysis and other end-use-computation. In this post, we will explore how we can use Databricks API to get data into Excel via Power Query.

Read More
Power Query use cases

How to get data from ZIP files using Power Query

Did you ever have to process data from Excel spreadsheets or CSV files locked inside a ZIP archive? With Power Query, you can seamlessly extract and analyse these files without manually unzipping the archive. This post walks you through extracting files from a ZIP archive, handling folder structures, and processing multiple file formats like .xlsx and .csv.

Read More

Leave a Reply

Your email address will not be published. Required fields are marked *