How do you implement blue-green deployments with serverless?

Answer

Blue-green deployments with Lambda use aliases and traffic shifting to deploy new versions without downtime or risk: (1) Lambda versions — each deployment creates an immutable version (v1, v2, v3). Aliases (e.g., LIVE, STAGING) point to specific versions; (2) Alias traffic shifting — configure the alias to route a percentage to two versions: aws lambda update-alias --function-name myFunc --name LIVE --routing-config AdditionalVersionWeights={\"3\"=0.1} — sends 10% to v3, 90% to previous version; (3) Canary deployment — start with 5% to new version, monitor error rates and latency in CloudWatch, gradually increase to 100% or roll back if issues detected; (4) CodeDeploy integration — AWS CodeDeploy automates canary/linear/all-at-once Lambda deployments with automatic rollback on CloudWatch alarms; (5) API Gateway stage variables — reference Lambda alias in API Gateway integration URL: arn:aws:lambda:region:account:function:myFunc:${stageVariables.lambdaAlias}; swap aliases atomically. AWS SAM and CDK both have built-in support for CodeDeploy Lambda deployments with DeploymentPreference configuration.