Lesson 21 / 32
Versions, Aliases and Safe Rollouts
Use immutable versions, aliases and weighted traffic to ship canary releases and roll back in seconds.
By Rahul Agarwal · 15 years in web development
Move a pointer, not the code
Deploying a function replaces code that thousands of requests a minute may be hitting, so platforms support safe rollouts. On Lambda, publishing creates an immutable, numbered version. An alias such as live is a named pointer to a version, and triggers call the alias. Rolling forward or back is then just moving the pointer. An alias can also split traffic by weight between two versions, which enables a canary: send 10% of traffic to the new version, watch error metrics, then shift the rest, or roll back automatically if an alarm fires. AWS SAM can drive this through CodeDeploy using AutoPublishAlias and a DeploymentPreference. Edge platforms offer comparable features, such as gradual deployments and instant rollback to an earlier deployment. Two rules keep rollbacks safe: keep database schema changes backward compatible for at least one release, and send every deploy through the pipeline, never through console edits.
A canary rollout in SAM
Each deploy publishes a new version, sends 10% of traffic to it for five minutes, then shifts the rest, unless the referenced alarm fires first and triggers a rollback.
OrderFunction:
Type: AWS::Serverless::Function
Properties:
Runtime: nodejs22.x
Handler: index.handler
CodeUri: src/
AutoPublishAlias: live
DeploymentPreference:
Type: Canary10Percent5Minutes
Alarms:
- !Ref OrderErrorsAlarmTrying a new bus route on one depot first
A city transport department testing a new timetable runs it from one depot for a week before rolling it out citywide. If complaints spike, only a few routes revert. A canary deploy does the same with a slice of your traffic.
Rollback breaks if the schema moved on
If version 2 renames a column and you roll back to version 1, version 1 crashes on the new schema. Use expand-and-contract migrations: add the new column, deploy code that writes both, migrate, and only drop the old column in a later release.
Quick check: In Lambda, what is an alias?
- A copy of the function deployed to another region
- An immutable snapshot of the function code
- An environment variable that stores the function name
- A named pointer to a version that can also split traffic between two versions
Answer
A named pointer to a version that can also split traffic between two versions — Versions are the immutable snapshots; an alias points at one (or weights two), so triggers need not change during a rollout.