0Pricing
Serverless Backend with AWS Lambda & API Gateway · Lesson

Safe Deployments with Canary and Rollback

Ship serverless changes without downtime. Learn Lambda aliases, weighted traffic shifting, CodeDeploy canary deployments, and automatic rollback on alarms.

Safe Deployments with Canary and Rollback is a free Serverless Backend with AWS Lambda & API Gateway lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Serverless Backend with AWS Lambda & API Gateway learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

The Risk of Big-Bang Deploys

Switching all traffic to new code at once means a bug hits every user instantly. Progressive deployments shift traffic gradually so problems surface on a small slice first.

Lambda Versions and Aliases

Publishing a Lambda creates an immutable version. An alias is a pointer (like live) you can move between versions, enabling controlled cutovers.

Weighted Aliases

An alias can split traffic between two versions by weight, sending, say, 10% to the new version and 90% to the old.

aws lambda update-alias \
  --function-name api --name live \
  --function-version 12 \
  --routing-config '{"AdditionalVersionWeights":{"11":0.9}}'

Canary Deployments

A canary sends a small percentage of traffic to the new version, waits, then promotes the rest if healthy. CodeDeploy automates this for Lambda.

Deployment Preferences in SAM

SAM exposes this via DeploymentPreference, choosing a canary or linear pattern.

AutoPublishAlias: live
DeploymentPreference:
  Type: Canary10Percent5Minutes
  Alarms:
    - !Ref ErrorAlarm

Linear Deployments

A linear pattern shifts traffic in equal increments over time (e.g. 10% every minute), giving a slower, steadier rollout than a single canary step.

CloudWatch Alarms as Gates

Attach alarms (error rate, latency) to the deployment. If an alarm fires during the shift, the deployment is considered failed.

Automatic Rollback

When an alarm trips, CodeDeploy automatically moves the alias back to the previous version, restoring known-good code with no manual action.

Pre and Post Traffic Hooks

Lifecycle hook Lambdas run before and after traffic shifts, letting you run smoke tests and abort the deploy if they fail.

Blue/Green vs Canary

Blue/green stands up a full second environment and switches over; canary shifts a percentage within one environment. For Lambda, weighted aliases make canary the simpler, cheaper default.

Best Practices

Deploy safely:

  • Always deploy behind an alias
  • Start with a small canary percentage
  • Gate on meaningful alarms
  • Run smoke tests in pre-traffic hooks

Quick Check

Test your safe-deployment knowledge.

Recap

You learned progressive delivery:

  • Versions are immutable; aliases point to them
  • Weighted aliases and canaries shift traffic gradually
  • SAM DeploymentPreference automates canary/linear patterns
  • Alarms gate the rollout and trigger automatic rollback

Frequently asked questions

Is the “Safe Deployments with Canary and Rollback” lesson free?

Yes — the full text of “Safe Deployments with Canary and Rollback” is free to read here on the web, and the Serverless Backend with AWS Lambda & API Gateway course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Serverless Backend with AWS Lambda & API Gateway course, upgrade to CoddyKit PRO.

What will I learn in “Safe Deployments with Canary and Rollback”?

Ship serverless changes without downtime. Learn Lambda aliases, weighted traffic shifting, CodeDeploy canary deployments, and automatic rollback on alarms. You practise Serverless Backend with AWS Lambda & API Gateway with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Serverless Backend with AWS Lambda & API Gateway?

No prior experience is required. Serverless Backend with AWS Lambda & API Gateway on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Safe Deployments with Canary and Rollback” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Serverless Backend with AWS Lambda & API Gateway lesson?

Yes. Every Serverless Backend with AWS Lambda & API Gateway lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. CodeCommit and CodeBuild
  2. CodePipeline for Deployments
  3. Automating Serverless Deployments
  4. Safe Deployments with Canary and Rollback
← Back to Serverless Backend with AWS Lambda & API Gateway