> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/aws/asg/asg-traffic-shift.md). Agents can also search and read this documentation through its [MCP server](https://developer.harness.io/~gitbook/mcp).

# ASG Blue-Green Traffic Shifting Step

ASG Blue-Green deployment strategy with native support for phased traffic shifting using ALB weighted target groups.

In the **ASG Blue-Green Traffic Shifting Step**, you define the production and stage listener ports and rules that the ASG Blue Green Deploy step uses. Then, the ASG Swap Services step shifts all traffic from the stage target group back to production.

A Blue/Green deployment ensures reliable updates by running both the new and existing ASGs behind an Application Load Balancer (ALB). The ALB uses two listeners, **stage** and **prod**, each forwarding to its corresponding target group, where the new and existing ASGs handle traffic.

**Advantages:**

* Configure multiple target groups in a **single rule** with adjustable traffic weights.
* Incrementally test new versions in development before rolling out to production.
* Implement gradual rollouts with approval gates between steps.
* Automatically revert to the original configuration if issues occur.

## What you will learn from this topic

* How to configure the ASG Blue Green Deploy step with load balancer and listener settings
* How to use the ASG Traffic Shift step to incrementally move traffic between stage and production target groups
* How to add approval gates between traffic shift phases for safe phased rollouts
* How to trigger rollback when a traffic shifting deployment fails

## Set up an ASG Blue-Green traffic shifting step group <a href="#set-up-an-asg-blue-green-traffic-shifting-step-group" id="set-up-an-asg-blue-green-traffic-shifting-step-group"></a>

To set up blue-green traffic shifting, do the following:

1. Add an ASG stage to your pipeline.
2. In that stage’s **Service** section, go to [Create a Harness ASG service](https://developer.harness.io/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/aws/asg/asg-tutorial.md#create-a-harness-asg-service) to add a Harness ASG service.
3. In the **Environment** section, go to [Create a Harness ASG environment](https://developer.harness.io/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/aws/asg/asg-tutorial.md#create-a-harness-asg-environment) to add a Harness ASG environment and infrastructure.
4. On the **Execution strategies** tab, choose **Blue Green**, then select **Add Traffic Shifting Steps** under **Enable Traffic Shifting for ECS Deployment**.

   Your **Execution** tab now shows a Blue Green Deployment group containing both **ASG Blue Green Deploy Step** and **ASG Traffic Shift**.

![Blue Green Deployment group with ASG Blue Green Deploy Step and ASG Traffic Shift](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-5a380810a3b22d282a937f13cc4d0f27e71bbd34%2Fasg-traffic-shift-1.png?alt=media)

If you do not select **Add Traffic Shifting Steps**, you instead see **ASG Blue Green Deploy Step** and **ASG Swap Service** in the group.

You can also start from a blank canvas and manually add **ASG Blue Green Deploy Step** and **ASG Traffic Shift** to your stage.

### Configure the ASG Blue Green Deploy step <a href="#configure-the-asg-blue-green-deploy-step" id="configure-the-asg-blue-green-deploy-step"></a>

The ASG Blue Green Deploy step has the following settings:

* **Name**: Logical name for the step.
* **Timeout**: Maximum execution duration.
* **App Name**: Name for the ASG application that Harness creates. You can use expressions such as `<+project.identifier>_<+service.identifier>_<+env.identifier>_basic2`, or set a fixed value or runtime input.
* **Instances**: Choose:
  * **Same as already running instances** to replicate existing capacity.
  * **Fixed**, then specify **Min Instances**, **Max Instances**, and **Desired Instances**.
* **Connected Cloud Provider**: Select the AWS connector and region explicitly; this is not inherited from your service or infrastructure.
* **AWS Load Balancer Configuration**: Click **Add** (or edit an existing entry):
  * **AWS Load Balancer**: Choose your load balancer.
  * Select **Use Shift Traffic** to enable the **ASG Blue-Green Traffic Shift** on this listener.
  * **Prod Listener**: Choose the ALB listener for production traffic.
  * **Prod Listener Rule ARN**: Select the listener rule that forwards to both stage and prod target groups, supporting weighted traffic distribution.

{% hint style="info" %}
If you do not select **Use Shift Traffic**, the **ASG Traffic Shift** step will be omitted from the pipeline.
{% endhint %}

![AWS Load Balancer Configuration settings](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-442c83c9e61dc5b32fe3e8ae359e63dbf16a248a%2Fasg-traffic-shift-2.png?alt=media)

You can define multiple **AWS Load Balancer Configuration** entries, each opting in or out of traffic shifting.

<details>

<summary>YAML sample for the step</summary>

```yaml
- step:
    name: Asg Blue Green Deploy
    identifier: AsgBlueGreenDeploy
    type: AsgBlueGreenDeploy
    timeout: 15m
    spec:
      instances:
        type: Fixed
        spec:
          min: 1
          max: 1
          desired: 1
      loadBalancers:
        - loadBalancer: asg-test
          prodListener: arn:..
          prodListenerRuleArn: arn:...
```

</details>

### Configure the ASG Traffic Shift step <a href="#configure-the-asg-traffic-shift-step" id="configure-the-asg-traffic-shift-step"></a>

The ASG Traffic Shift step has the following settings:

* **Name**: Logical name for the step.
* **Timeout**: Maximum execution duration.
* **New Autoscaling Group Weight (%)**: Enter the percentage of traffic to shift to the new ASG.

  ![New Autoscaling Group Weight setting](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-aa92a0c17d40568be9fd5d76a96cb55832004f5a%2Fasg-traffic-shift-3.png?alt=media)
* **Delete old ASG**: select this option to permanently delete the old ASG after Harness shifts traffic fully to the new ASG and downsizes the old one. This option is available only on the step that shifts weight to 100%, and requires **Downsize Old ASG** to also be enabled on that step.

  <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p>This feature is behind the feature flag <code>CDS_ASG_DELETE_OLD_ASG</code>. Contact <a href="mailto:support@harness.io">Harness Support</a> to enable the feature.</p></div>

  Rollback cannot restore an ASG that has already been deleted. If a later step fails and triggers rollback, Harness skips shifting traffic back to the deleted ASG, leaves the new ASG serving, and the rollback step completes with a warning.

The following is a demo video of Blue Green with incremental traffic shift:

{% embed url="<https://www.loom.com/share/5193b65dafa34d63921efc6f0c7fa798?sid=0ea60fd7-376d-4c92-a2ee-dfe47af6075b>" %}

This approach lets you incrementally shift production traffic from your existing ASG to the new one:

* Add multiple ASG Traffic Shift steps (you can intersperse approval steps as needed).
* In the first ASG Traffic Shift step, set New Autoscaling Group Weight to the desired percentage.
* Repeat for subsequent steps.
* Enable Downsize Old ASG at 0% weight only on the step that shifts to 100%. This automatically scales down the old ASG.
* Optionally enable Delete old ASG alongside Downsize Old ASG on that same 100% step to also delete the old ASG once Harness downsizes it.

## Advanced settings <a href="#advanced-settings" id="advanced-settings"></a>

In the **Advanced** settings of all step, you can use the following options:

* [Delegate Selector](https://developer.harness.io/docs/platform/delegates/delegate/manage-delegates/select-delegates-with-selectors)
* [Conditional Execution](https://developer.harness.io/docs/platform/pipelines/step-skip-condition-settings)
* [Failure Strategy](https://developer.harness.io/docs/platform/pipelines/failure-handling/define-a-failure-strategy-on-stages-and-steps)
* [Looping Strategy](https://developer.harness.io/docs/platform/pipelines/looping-strategies/looping-strategies-matrix-repeat-and-parallelism)
* [Policy Enforcement](https://developer.harness.io/docs/platform/governance/policy-as-code/harness-governance-overview)

## Sample pipeline YAML for traffic shifting step <a href="#sample-pipeline-yaml-for-traffic-shifting-step" id="sample-pipeline-yaml-for-traffic-shifting-step"></a>

Below is a ready-to-use pipeline YAML that demonstrates how to configure the traffic shifting mode in an ASG Blue-Green deployment.

<details>

<summary>Sample YAML</summary>

```yaml
pipeline:
  name: PIPELINE_NAME
  identifier: PIPELINE_ID
  projectIdentifier: PROJECT_ID
  orgIdentifier: ORG_ID
  tags: {}
  stages:
    - stage:
        name: DeployBG
        identifier: DeployBG
        description: ""
        type: Deployment
        spec:
          deploymentType: Asg
          service:
            serviceRef: AsgService_6SIiP
            serviceInputs:
              serviceDefinition:
                type: Asg
                spec:
                  artifacts:
                    primary:
                      primaryArtifactRef: AMI-ARTIFACT
          environment:
            environmentRef: AsgEnv
            deployToAll: false
            infrastructureDefinitions:
              - identifier: AsgInfra
          execution:
            steps:
              - stepGroup:
                  name: Blue Green Deployment
                  identifier: blueGreenDeployment
                  steps:
                    - step:
                        name: Asg Blue Green Deploy
                        identifier: AsgBlueGreenDeploy
                        type: AsgBlueGreenDeploy
                        timeout: 15m
                        spec:
                          instances:
                            type: Fixed
                            spec:
                              min: 1
                              max: 1
                              desired: 1
                          loadBalancers:
                            - loadBalancer: asg-ng-test
                              prodListener: arn:aws:elasticloadbalancing:us-east-1...
                              prodListenerRuleArn: arn:aws:elasticloadbalancing:us-east-1...
                    - step:
                        name: AsgShiftTraffic30
                        identifier: AsgShiftTraffic30
                        type: AsgShiftTraffic
                        timeout: 15m
                        spec:
                          weight: 30
                          downsizeOldAsg: false
                    - step:
                        name: AsgShiftTraffic100
                        identifier: AsgShiftTraffic100
                        type: AsgShiftTraffic
                        timeout: 15m
                        spec:
                          weight: 100
                          downsizeOldAsg: true
                          deleteOldAsg: true
            rollbackSteps:
              - step:
                  name: Asg Blue Green Rollback
                  identifier: AsgBlueGreenRollback
                  type: AsgBlueGreenRollback
                  timeout: 10m
                  spec: {}
        tags: {}
        failureStrategies:
          - onFailure:
              errors:
                - AllErrors
              action:
                type: StageRollback

```

</details>

## Next steps

* [ASG deployments](https://developer.harness.io/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/aws/asg/asg-tutorial.md)
* [Deployment concepts and strategies](https://developer.harness.io/continuous-delivery/use-continuous-delivery/manage-deployments/deployment-concepts.md)
* [CD best practices](https://developer.harness.io/continuous-delivery/troubleshooting-and-resources/cd-best-practices.md)

{% @harness-feedback/feedback %}
