Blue-Green Deployment
Learn about the blue-green deployment technique for ensuring our application’s stability during deployment.
The challenge in production
So, we have our Step Functions workflow running smoothly, orchestrating our AWS Lambda functions. We need to keep in mind that we work in an ever-changing environment. Imagine this scenario:
We have a long-running workflow that’s busy processing data. In the meantime, one of our colleagues pushes a new update to one of the Lambda functions within that workflow. Suddenly, our workflow, which started under one version of the function, now has to deal with a new version partway through its execution.
This could lead to a range of problems, from minor bugs to significant workflow failures. In short, we’re introducing unnecessary risk into our production environment.
Enter Lambda function aliases and versions
To better manage and control this situation, AWS Lambda provides the concept of function versions and aliases.
Every time we update our function’s code or configuration, Lambda creates a new immutable version of the function. The latest version is always tagged as $LATEST
.
An alias in Lambda is a pointer to a specific function version. It’s a way to reference a particular function version without having to know the exact version number. We can create aliases such as PROD
or STAGE
and then have them point to the specific function version we want to use in that environment.
Deployment strategy
The blue-green deployment strategy is a way to reduce downtime and risk by running two identical production environments—blue and green.
At any time, only one of the environments is live. Let’s say the blue environment is live. As we prepare a new version of our application, we do our final stage of testing in the green environment. Once tested and ready for production, we switch the router so all incoming requests now go to the green environment, making it live. The blue environment is now idle.
In the context of Step Functions and Lambda, we can think of the blue environment as the currently active version of our functions, while the green environment represents the new, updated versions.
To perform a blue-green deployment, we can create new versions of our functions and then gradually shift the aliases (like PROD
) to point to these new versions. As a result, any new execution of our Step Functions state machine will use the updated functions, while ongoing executions will continue with the function versions they started with.
Serverless Framework to the rescue
The Serverless Framework simplifies blue-green deployment with the useExactVersion: true
configuration option for our state machines:
Get hands-on with 1200+ tech skills courses.