Skip to main content
In this lesson we cover Lambda versioning, aliases, and traffic-shifting strategies commonly used in serverless deployments: blue/green, canary, and linear rollouts. These topics are essential for controlled releases, fast rollbacks, and are exam-relevant for the AWS Certified DevOps Engineer — Professional. We use the demo function devops-020-320-function to demonstrate how published versions and aliases enable predictable rollouts and safe production traffic management.

Lambda versioning basics

Key concepts:
  • Publishing a version creates an immutable snapshot of the function’s code and configuration.
  • The special identifier \$LATEST is mutable — it always refers to the most recent un-published state (it changes whenever you update code or configuration).
  • A qualified ARN (for example, arn:aws:lambda:us-east-1:598274344262:function:devops-020-320-function:6) targets a specific published version.
  • Aliases are named pointers to versions (for example, prod, staging, live) and provide stable references for production invocations.
When you publish versions you can:
  • Pin an alias to a single version (100% traffic to that version).
  • Configure a weighted alias to split traffic between two versions (Lambda supports weights for up to two versions per alias).
A screenshot of the AWS Lambda console on the "Versions" tab for the function named "devops-020-320-function," showing multiple published versions (3–6) with an alias "live." The page also shows buttons to add a trigger/destination and options to publish or delete versions.
Important operational note: once a version is published it cannot be modified. Invoking a function without a qualifier calls whatever \$LATEST currently is, which is unstable for production.
Do not rely on \$LATEST for production traffic. Use aliases pinned to specific published versions for stable, auditable invocations and reproducible rollbacks.

Quick CLI examples

  • Publish a new version:
  • Create an alias that points to a specific version:
  • Create a weighted alias (90% to v6, 10% to v5):

Aliases and weighted traffic shifting

Aliases are friendly, stable names that point to either a single version or a weighted split between two versions. Common uses:
  • Pin an alias to a single published version for stable traffic (example: prod -> 6).
  • Split traffic between two versions via weights for gradual rollouts (example: prod -> 90% v6, 10% v5).
Lambda supports weighting for up to two versions per alias; for more advanced patterns or automated scheduling you should use CodeDeploy.
A screenshot of the AWS Lambda console for the function "devops-020-320-function" showing the Aliases tab and a green banner saying "Alias prod was successfully created." The aliases table lists "live" and "prod," with prod routing traffic to versions 6 and 5 (weights 90% and 10%).
Monitor alias-level metrics in CloudWatch (invocations, errors, duration, throttles) to validate a rollout. If the new version behaves poorly, re-pin the alias to the previous version to roll back instantly.

When to use CodeDeploy for Lambda

Manual alias updates or scripted changes work for simple rollouts, but CodeDeploy provides robust, automated traffic-shifting strategies and integrates with CI/CD pipelines (CodePipeline). Benefits include:
  • Built-in patterns: canary (small initial percentage), linear (incremental steps), and all-at-once.
  • Lifecycle hooks: BeforeAllowTraffic and AfterAllowTraffic to run validation or smoke-tests.
  • Alarm-based rollback: integrate CloudWatch alarms to trigger automatic rollbacks.
  • Detailed deployment history, tags, and deployment-group management for traceability.
Use CodeDeploy when you need automated canary/linear deployments, lifecycle hooks, or alarm-driven rollbacks as part of a production-ready CI/CD pipeline.
To use CodeDeploy with Lambda you supply an AppSpec file that describes the Lambda function, alias, current/target versions, and hooks. Example AppSpec YAML:
  • BeforeAllowTraffic: run validations before new traffic is allowed.
  • AfterAllowTraffic: run smoke tests after traffic starts flowing to the target.
Make sure the hook functions and the specified versions/aliases exist; otherwise deployments will fail and CodeDeploy may trigger a rollback.
A screenshot of the AWS CodeDeploy "Create deployment" page showing deployment group overrides and rollback configuration options. A red error banner at the bottom says "No Deployment Group found for name: devops-020-20-canry," and the "Create deployment" button is visible.
If the target Lambda, version, or alias is missing or misconfigured, deployments will fail:
A screenshot of the AWS CodeDeploy console showing deployment d-94B4N5CEI failed. A red error banner states the target Lambda function "devops-demo-function" or the specified version/alias cannot be found, and the Deployment details show status "Failed."
CodeDeploy deployment groups provide metadata and history so you can trace failures and investigate rollbacks:
A screenshot of the AWS CodeDeploy console showing Deployment group tags (Environment: learning, Purpose: devops-professional-exam-prep, Demo: 020-320, ManagedBy: terraform) and the deployment history panel listing failed deployments and a CodeDeploy rollback.

Practical tips and important limits

  • Always invoke stable aliases in production instead of \$LATEST.
  • Weighted aliases support at most two versions per alias. For multi-step rollouts, use CodeDeploy or manage multiple aliases programmatically.
  • Use CodeDeploy for scheduled or automated canary/linear rollouts, hook execution, and alarm-based rollback.
  • CloudWatch alarms can trigger rollbacks within CodeDeploy deployment configurations.
  • AWS SAM and API Gateway also provide deployment/canary features — choose based on your pipeline and operational needs.
  • Consider SnapStart (for supported runtimes like Java) or provisioned concurrency to reduce cold-start latency for heavy runtimes.
You can manage versions, aliases, and many Lambda settings (memory, ephemeral storage, environment variables, permissions, URLs) in the Lambda console. SnapStart publishes cached snapshots of a version which can improve startup latency for supported runtimes.
Screenshot of the AWS Lambda console on the "Aliases" tab for the function devops-020-320-function, with a green banner stating "Alias test was successfully created and is now pointing to versions 5 and 6." The aliases table lists "live", "prod", and "test" entries (with version numbers and traffic weights) and the function ARN is visible on the right.
A screenshot of the AWS Lambda console "Edit basic settings" page showing configuration fields (Memory 256 MB, Ephemeral storage 512 MB, SnapStart set to PublishedVersions, Timeout 0:30) and an on-screen green banner saying "Alias test was successfully created."

Deployment patterns — quick comparison

Summary — exam-relevant points

  • \$LATEST is mutable and changes with every update; do not use it as a production reference.
  • Aliases are stable references; use them for production traffic and auditability.
  • Weighted aliases support at most two versions per alias for traffic splitting.
  • Use CodeDeploy for automated canary/linear deployments, lifecycle hooks, and alarm-based rollback.
  • Understand the differences between canary (small then full), linear (incremental), and all-at-once deployments.
Further reading and references: Understanding Lambda versioning, aliases, and CodeDeploy traffic-shifting options is both practically useful and commonly tested on the DevOps Professional exam.

Watch Video