Implementing Blue/Green Deployments with AWS Lambda
Instruction: Describe how you would implement blue/green deployments for AWS Lambda functions to reduce downtime and risk during updates.
Updated
Official answer
Publish immutable versions of the same Lambda function and configure clients/event sources to invoke a stable alias. Validate the candidate version against representative events and compatible dependencies before changing that alias.
For an immediate blue/green switch, move the alias from the old version to the new one. For a gradual canary, use a weighted alias across two eligible published versions of that same function, or automate the shift with CodeDeploy/SAM and validation hooks. An alias cannot route between two separately created functions, and Route 53 does not itself split individual Lambda invocations.
Weighted routing is probabilistic, so a small sample need not contain exactly the configured percentage. Monitor the executed version's errors, latency, throttles and business failures, with enough traffic and time to assess it. Ensure provisioned capacity and permissions match the alias/version plan.
Keep database schemas and events compatible with both versions during the overlap. On a regression, stop the rollout and restore alias routing to the tested version. This affects future routing; it does not cancel in-flight invocations or undo writes, sent messages or schema migrations. Test recovery from those side effects separately and retain the old artifact until rollback is no longer required.