Back to results for “CI/CD”
AWS › AWS Serverless Application Model (SAM)

How does SAM support safe, gradual Lambda deployments using traffic shifting and automatic rollback?

Intermediate

Answer

SAM integrates with CodeDeploy to support gradual traffic shifting deployment strategies for Lambda functions, such as shifting ten percent of traffic to a new function version at a time over several minutes, combined with CloudWatch alarms that automatically trigger a rollback to the previous version if errors increase during the rollout, providing a much safer deployment process than immediately shifting one hundred percent of traffic to an unproven new version.
Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      AutoPublishAlias: live
      DeploymentPreference:
        Type: Canary10Percent5Minutes
        Alarms:
          - !Ref ErrorAlarm
Real-world example A payment processing team configures their SAM template to use a canary deployment strategy, automatically rolling back a Lambda function update if error rates spike during the initial ten percent traffic shift, preventing a bad deployment from ever reaching all customers.

Common follow-ups: What deployment preference types does SAM support besides Canary?;How quickly does an automatic rollback trigger once an alarm threshold is breached?