> 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/new-experience/use-deployments/ecs-deployments/step-library/ecs-bluegreen-swap-target-groups.md). Agents can also search and read this documentation through its [MCP server](https://developer.harness.io/~gitbook/mcp).

# ECS BlueGreen Swap Target Groups step

The ECS BlueGreen Swap Target Groups step swaps the production and staging ALB target groups, shifting all traffic to the newly deployed green service.

The ECS BlueGreen Swap Target Groups step runs after ECS BlueGreen Deploy in the swap target groups variant. It swaps the target groups on the production and staging ALB listeners, directing all production traffic to the newly deployed green service. Its inputs are wired entirely from the ECS BlueGreen Deploy step's outputs.

**Step Template ID:** `ecsBluegreenSwapTargetGroupsStep`

***

## ECS BlueGreen Swap Target Groups step YAML

```yaml
- name: ECS BlueGreen Swap Target Groups
  id: ecsBluegreenSwapTargetGroupsStep
  deploy:
    uses: ecsBluegreenSwapTargetGroupsStep
    with:
      not_downsize_old: false
      downsize_delay: 0s
      skip_steady_state: false
      steady_state_timeout: 10m
      load_balancer: ${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.loadBalancer}}
      prod_listener_arn: ${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.prodListenerArn}}
      prod_listener_rule_arn: ${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.prodListenerRuleArn}}
      prod_target_group_arn: ${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.prodTargetGroupArn}}
      stage_listener_arn: ${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.stageListenerArn}}
      stage_listener_rule_arn: ${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.stageListenerRuleArn}}
      stage_target_group_arn: ${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.stageTargetGroupArn}}
      blue_service: ${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.serviceName}}
      green_service: ${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.greenServiceName}}
      first_deployment: ${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.firstDeployment}}
      connector: ${{infra.connectorRef}}
      region: ${{infra.region}}
      cluster: ${{infra.cluster}}
      log_level: info
```

***

## Before you begin

* **An ECS service:** Go to [ECS services](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/ecs-services.md) to set up a service with a task definition and artifact source.
* **An ECS infrastructure definition:** Go to [ECS infrastructure](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/ecs-infrastructure.md) to connect an AWS account and configure authentication.

***

## ECS BlueGreen Swap Target Groups step fields

These fields identify which listeners, target groups, and services to swap. All of them are wired from the ECS BlueGreen Deploy step's outputs and do not need to be changed.

| Field                       | YAML key                  | Description                                                                                             |
| --------------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------- |
| **Elastic Load Balancer**   | `load_balancer`           | Wired from the ECS BlueGreen Deploy step's `loadBalancer` output.                                       |
| **Prod Listener ARN**       | `prod_listener_arn`       | Wired from the `prodListenerArn` output.                                                                |
| **Prod Listener Rule ARN**  | `prod_listener_rule_arn`  | Wired from the `prodListenerRuleArn` output.                                                            |
| **Prod Target Group ARN**   | `prod_target_group_arn`   | Wired from the `prodTargetGroupArn` output. The target group currently receiving production traffic.    |
| **Stage Listener ARN**      | `stage_listener_arn`      | Wired from the `stageListenerArn` output.                                                               |
| **Stage Listener Rule ARN** | `stage_listener_rule_arn` | Wired from the `stageListenerRuleArn` output.                                                           |
| **Stage Target Group ARN**  | `stage_target_group_arn`  | Wired from the `stageTargetGroupArn` output. The target group the green service was registered against. |
| **Blue Service**            | `blue_service`            | Wired from the `serviceName` output. The current (blue) production service.                             |
| **Green Service**           | `green_service`           | Wired from the `greenServiceName` output. The newly deployed green service.                             |
| **First Deployment**        | `first_deployment`        | Wired from the `firstDeployment` output.                                                                |

### Swap configuration

| Field                           | YAML key               | Default | Description                                                                                     |
| ------------------------------- | ---------------------- | ------- | ----------------------------------------------------------------------------------------------- |
| **Do Not Downsize Old Service** | `not_downsize_old`     | `false` | When `true`, Harness does not downsize the old (now staging) service after the swap.            |
| **Downsize Delay**              | `downsize_delay`       | `0s`    | How long Harness waits after the swap before downsizing the old service.                        |
| **Skip Steady State**           | `skip_steady_state`    | `false` | When `true`, Harness does not wait for the new service to reach steady state before proceeding. |
| **Steady State Timeout**        | `steady_state_timeout` | `10m`   | How long Harness waits for the new service to reach steady state.                               |

### Other configuration

| Field         | YAML key    | Default | Description                           |
| ------------- | ----------- | ------- | ------------------------------------- |
| **Log Level** | `log_level` | `info`  | Log verbosity for the step execution. |

### Infrastructure configuration

These fields are derived from the infrastructure definition. Harness resolves them automatically.

| Field         | YAML key    | Default value             | Description                                              |
| ------------- | ----------- | ------------------------- | -------------------------------------------------------- |
| **Connector** | `connector` | `${{infra.connectorRef}}` | The AWS connector from the infrastructure definition.    |
| **Region**    | `region`    | `${{infra.region}}`       | The AWS region from the infrastructure definition.       |
| **Cluster**   | `cluster`   | `${{infra.cluster}}`      | The ECS cluster name from the infrastructure definition. |

***

## How the ECS BlueGreen Swap Target Groups step works

When the step runs, Harness executes the following actions:

1. Reads the listener, listener rule, and target group ARNs, and the blue and green service names, from the ECS BlueGreen Deploy step outputs (or auto-resolves them when a field is left unset).
2. Swaps the target group associations on the production and staging ALB listeners, so the production listener now routes to the new (green) service and the staging listener now routes to the old (blue) service.
3. Waits for the new service to reach steady state (unless **Skip Steady State** is enabled).
4. Downsizes the old (now staging) service, after the configured delay, unless **Do Not Downsize Old Service** is enabled.
5. Collects running task data from both services for the Harness deployment dashboard.

***

## Next steps

* Go to [ECS BlueGreen Deploy step](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/step-library/ecs-bluegreen-deploy.md) for the step that precedes this one and emits the outputs this step consumes.
* Go to [ECS BlueGreen Rollback step](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/step-library/ecs-bluegreen-rollback.md) for the rollback step for this strategy.
* Go to [ECS step library](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/step-library.md) for the full list of available steps.
