Lesson 3 of 3 Deployment Strategies Across Compute Platforms

Shifting Traffic with DNS, Load Balancers, Edge Services and Feature Flags

Blue/green and canary releases need a mechanism that sends a controlled share of requests to the new version. AWS provides several such mechanisms at different layers. This lesson explains weighted Route 53 records, Application Load Balancer weighted target groups, CloudFront continuous deployment, API Gateway canary releases and Lambda alias routing, and shows how feature flags separate deployment from release.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain how Route 53 weighted routing implements blue/green and canary releases and why DNS caching limits it.
  • Describe how ALB weighted target groups shift traffic and how target group stickiness affects them.
  • Describe CloudFront continuous deployment and API Gateway canary release settings.
  • Explain how feature flags separate deploying code from releasing features.

Route 53 Weighted Routing

Amazon Route 53 weighted records return different answers for the same name in proportion to their weights. A blue/green or canary release can create a record for each environment, such as weight 90 for blue and 10 for green, and adjust the weights over time. This works for any endpoint with a DNS name, including load balancers in different Regions or entire stacks, and health checks on the records remove an unhealthy environment from answers.

DNS-based shifting has an important limitation: resolvers and clients cache answers for the record's TTL, and some clients ignore TTLs. Shifting traffic is therefore gradual and imprecise, and rollback is not immediate. Lowering the TTL, for example to 60 seconds, well before the release reduces the effect. Alias records to AWS resources have no configurable TTL of their own; Route 53 uses the TTL of the target resource's records.

Application Load Balancer Weighted Target Groups

An ALB listener rule's forward action can distribute requests across up to five target groups with weights from 0 to 999. Blue and green environments are registered in separate target groups, and changing the weights shifts traffic immediately for new requests, without DNS caching. This makes ALB weighted routing more precise and faster to roll back than DNS. It requires both environments to be behind the same load balancer, which is typical within one Region.

Target group stickiness, set on the forward action, keeps a client on the target group it first reached for a duration, so users do not switch between versions during a session. Stickiness slows the shift, because existing clients stay on blue until their stickiness expires. ECS native blue/green and CodeDeploy blue/green deployments use this listener mechanism internally.

CloudFront Continuous Deployment

Changes to an Amazon CloudFront distribution's configuration, such as cache behaviours, origins or functions, affect all users when deployed. CloudFront continuous deployment lets a team create a staging distribution with the changed configuration, linked to the primary distribution by a continuous deployment policy. The policy routes a share of requests to the staging configuration either by weight (up to 15% of requests, with optional session stickiness) or by a specific request header, which testers can send. When the change is validated, the staging configuration is promoted to the primary distribution. This provides canary testing for the edge configuration itself, while the origin applications are released by their own mechanisms.

API Gateway Canary Releases and Lambda Alias Routing

An Amazon API Gateway REST API stage can have canary settings: a percentage of requests is sent to a canary deployment of the API, and stage variables can be overridden for the canary, for example to point a Lambda integration at a different alias. Canary requests produce separate logs and metrics. When the canary is validated, it is promoted, making the canary deployment the stage's deployment, or it is removed. HTTP APIs do not have canary settings, so for them the shifting is usually done at the Lambda alias level.

Lambda weighted aliases, described in the CodeDeploy module, shift invocations between function versions regardless of how the function is invoked, and CodeDeploy automates the weights with canary and linear configurations.

The following table compares the traffic-shifting mechanisms.

MechanismLayerPrecision and speedTypical use
Route 53 weighted recordsDNSApproximate; delayed by cachingShifting between Regions or whole stacks
ALB weighted target groupsLoad balancerPrecise; immediate for new requestsBlue/green within a Region on EC2 or ECS
CloudFront continuous deploymentEdge configurationUp to 15% by weight, or by headerTesting distribution configuration changes
API Gateway canaryAPI stagePercentage of requestsReleasing REST API changes
Lambda weighted aliasFunctionPercentage of invocationsReleasing function versions with CodeDeploy

Feature Flags: Separating Deployment from Release

All the mechanisms above route requests between deployed versions. Feature flags work differently: new code is deployed to every instance but stays inactive until a flag is switched on. The application checks the flag at run time, so a feature can be enabled for internal users first, then for a percentage of customers, and switched off instantly if it causes problems, without any deployment.

On AWS, feature flags are managed with AWS AppConfig, which stores flag configurations, validates them, deploys flag changes gradually with deployment strategies and rolls them back automatically when CloudWatch alarms fire. Applications retrieve flags through the AppConfig Agent, which caches them locally. AppConfig is explained in detail in the configuration management module. Flags are particularly valuable in trunk-based development, where incomplete features must be merged to main without being visible to users, and for operational kill switches that disable an expensive feature during an incident.

The following diagram separates the deployment from the stages of the release.

Feature flags separate deployment from release. The new code is deployed to every instance with its flag off, so users see no change. The flag is then enabled for internal users, then for a percentage of customers, then for everyone, without another deployment, and it can be switched off instantly as a kill switch. AWS AppConfig stores and validates the flag, deploys flag changes gradually with alarm-based rollback, and applications read it through the AppConfig Agent's local cache.
Releasing becomes a configuration change rather than a deployment.

Flag hygiene

Flags have a cost: each flag adds code paths to test and remove later. Short-lived release flags should be deleted once the feature is fully released, while long-lived operational flags are documented as part of the runbook.

Sort into groups

Choose the traffic-shifting mechanism

Exam skills 1.4.4 · 3.2.4

Choose the mechanism that shifts traffic for each release.

Log in to try this activity Interactive activities are free with an account.
Worked example

A Multi-Layer Release

A media company releases a new recommendation feature. The feature involves a new version of an ECS service behind an ALB, a CloudFront cache behaviour change and new API logic. The company wants internal staff to try the feature first, then 5% of customers, with immediate rollback.

  1. Deploy the code dark

    Deploy the new ECS service version with a native canary deployment; the feature code is present but its AppConfig flag is off, so customers see no change.

  2. Test the edge change

    Create a CloudFront staging distribution with the new cache behaviour and route requests with a test header to it for staff.

  3. Release gradually

    Enable the flag for staff, then use an AppConfig deployment strategy to roll the flag out to 5% of customers with an alarm-based rollback.

  4. Complete

    Promote the staging distribution and roll the flag out to everyone; remove the flag in a later release.

Check yourself

After changing Route 53 weights to send all traffic to the green environment, some users still reach blue for several minutes. Why, and how could the delay be reduced?

Show answer

Resolvers and clients cache DNS answers for the record's TTL, and some ignore it. Lowering the TTL before the release reduces the delay; using ALB weighted target groups avoids DNS caching altogether within a Region.

Exam Tips

Remember for the exam

  • Route 53 weighted records shift traffic between Regions or stacks, but DNS caching makes shifts and rollbacks gradual; lower TTLs before a release.
  • ALB weighted target groups (up to five, weights 0 to 999) shift traffic immediately; stickiness keeps clients on one version.
  • CloudFront continuous deployment uses a staging distribution with weight-based (up to 15%) or header-based routing, then promotion.
  • API Gateway REST API stages support canary settings with stage variable overrides; promote or remove the canary.
  • Feature flags in AWS AppConfig separate deployment from release and allow instant rollback without a deployment.