> 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-deploy.md). Agents can also search and read this documentation through its [MCP server](https://developer.harness.io/~gitbook/mcp).

# ECS BlueGreen Deploy step

The ECS BlueGreen Deploy step creates or updates the green ECS service with the new task definition and configures ALB listener routing for blue-green traffic management.

The ECS BlueGreen Deploy step is the first step in both blue-green variants. It registers a new task definition revision, creates or updates the green service (the staging slot), applies auto-scaling, and emits step output variables that downstream steps and the rollback step use to manage the traffic swap or shift.

**Step Template ID:** `ecsBluegreenDeployStep`

***

## ECS BlueGreen Deploy step YAML

```yaml
- name: ECS BlueGreen Deploy
  id: ecsBluegreenDeployStep
  deploy:
    uses: ecsBluegreenDeployStep
    with:
      load_balancer: my-load-balancer
      traffic_shift: false
      prod_listener_arn: arn:aws:elasticloadbalancing:<region>:<account>:listener/...
      prod_listener_rule_arn: arn:aws:elasticloadbalancing:<region>:<account>:listener-rule/...
      stage_listener_arn: arn:aws:elasticloadbalancing:<region>:<account>:listener/...
      stage_listener_rule_arn: arn:aws:elasticloadbalancing:<region>:<account>:listener-rule/...
      update_green_svc: false
      remove_autoscaling_blue_svc: false
      skip_steady_state: false
      steady_state_timeout: 10m
      task_def_mode: Task Definition
      task_def: ${{serviceOutput.manifests.ecsTaskDefinition.paths}}
      service_def: ${{serviceOutput.manifests.ecsServiceDefinition.paths}}
      scalable_targets: ${{serviceOutput.manifests.ecsScalableTarget.paths}}
      scaling_policies: ${{serviceOutput.manifests.ecsScalingPolicy.paths}}
      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 Deploy step fields

### Load balancer configuration

| Field                       | YAML key                  | Required | Default | Description                                                                                                       |
| --------------------------- | ------------------------- | -------- | ------- | ----------------------------------------------------------------------------------------------------------------- |
| **Elastic Load Balancer**   | `load_balancer`           | Yes      | —       | The name of the Application Load Balancer that routes traffic to the ECS service.                                 |
| **Prod Listener ARN**       | `prod_listener_arn`       | Yes      | —       | The ARN of the production ALB listener.                                                                           |
| **Prod Listener Rule ARN**  | `prod_listener_rule_arn`  | Yes      | —       | The ARN of the production listener rule that directs traffic to the production target group.                      |
| **Stage Listener ARN**      | `stage_listener_arn`      | Yes      | —       | The ARN of the staging ALB listener.                                                                              |
| **Stage Listener Rule ARN** | `stage_listener_rule_arn` | No       | —       | The ARN of the staging listener rule. Required when using listener rules rather than the default listener action. |

### Deployment configuration

| Field                               | YAML key                      | Default | Description                                                                                                                                                                                                                                                                                             |
| ----------------------------------- | ----------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Traffic Shift**                   | `traffic_shift`               | `false` | Set to `true` when this step is paired with [ECS BlueGreen Traffic Shift](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/step-library/ecs-bluegreen-traffic-shift.md) instead of ECS BlueGreen Swap Target Groups. Leave `false` for the swap variant. |
| **Update Green Service**            | `update_green_svc`            | `false` | When `true`, Harness updates an existing green service if one is already running, rather than creating a new one.                                                                                                                                                                                       |
| **Remove Autoscaling Blue Service** | `remove_autoscaling_blue_svc` | `false` | When `true`, Harness removes auto-scaling configuration from the blue (current production) service after the green service is created.                                                                                                                                                                  |
| **Skip Steady State**               | `skip_steady_state`           | `false` | When `true`, Harness does not wait for the green service to reach steady state before proceeding.                                                                                                                                                                                                       |
| **Steady State Timeout**            | `steady_state_timeout`        | `10m`   | How long Harness waits for the green service to reach steady state.                                                                                                                                                                                                                                     |

### Service configuration

Auto-resolved from the service and artifact configuration.

| Field                      | YAML key           | Default value                                             | Description                                                 |
| -------------------------- | ------------------ | --------------------------------------------------------- | ----------------------------------------------------------- |
| **Task Definition Mode**   | `task_def_mode`    | `Task Definition`                                         | The task definition format.                                 |
| **ECS Task Definition**    | `task_def`         | `${{serviceOutput.manifests.ecsTaskDefinition.paths}}`    | Path to the task definition file.                           |
| **ECS Service Definition** | `service_def`      | `${{serviceOutput.manifests.ecsServiceDefinition.paths}}` | Path to the service definition file.                        |
| **Scalable Targets**       | `scalable_targets` | `${{serviceOutput.manifests.ecsScalableTarget.paths}}`    | Path to the scalable target manifest for the green service. |
| **Scaling Policies**       | `scaling_policies` | `${{serviceOutput.manifests.ecsScalingPolicy.paths}}`     | Path to the scaling policy manifest for the green service.  |

### 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 Deploy step works

When the step runs, Harness executes the following actions in order:

1. Registers a new ECS task definition revision from the task definition manifest.
2. Identifies the current production (blue) service and the green (staging) service using the ALB listener target group associations.
3. Creates or updates the green service with the new task definition.
4. Waits for the green service to reach steady state (unless **Skip Steady State** is enabled).
5. Registers scalable targets and scaling policies on the green service.
6. Captures rollback data internally (available to the rollback steps through `${{rollback.data.*}}` expressions) and emits output variables, including the production and green service names and the resolved listener and target group ARNs, for use by ECS BlueGreen Swap Target Groups and ECS BlueGreen Rollback.

***

## Step outputs

| Output                 | Expression                                                                            | Description                                                                                                  |
| ---------------------- | ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| `serviceName`          | `${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.serviceName}}`          | The name of the current (blue) production service before the swap.                                           |
| `greenServiceName`     | `${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.greenServiceName}}`     | The name of the green (new) service that was deployed.                                                       |
| `firstDeployment`      | `${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.firstDeployment}}`      | Whether this was the first deployment to this cluster.                                                       |
| `greenServiceExisted`  | `${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.greenServiceExisted}}`  | Whether the green service existed before this deployment.                                                    |
| `loadBalancer`         | `${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.loadBalancer}}`         | The load balancer name, passed through for downstream steps.                                                 |
| `prodListenerArn`      | `${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.prodListenerArn}}`      | The production listener ARN, passed through for downstream steps.                                            |
| `prodListenerRuleArn`  | `${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.prodListenerRuleArn}}`  | The production listener rule ARN, passed through for downstream steps.                                       |
| `prodTargetGroupArn`   | `${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.prodTargetGroupArn}}`   | The target group ARN currently associated with the production listener.                                      |
| `stageListenerArn`     | `${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.stageListenerArn}}`     | The staging listener ARN, passed through for downstream steps.                                               |
| `stageListenerRuleArn` | `${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.stageListenerRuleArn}}` | The staging listener rule ARN, passed through for downstream steps.                                          |
| `stageTargetGroupArn`  | `${{stage.steps.ecsBluegreenDeployStep.output.outputVariables.stageTargetGroupArn}}`  | The target group ARN currently associated with the staging listener, where the green service was registered. |

The [ECS BlueGreen Swap Target Groups step](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/step-library/ecs-bluegreen-swap-target-groups.md) wires all of these outputs into its own `with:` inputs. The [ECS BlueGreen Rollback step](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/step-library/ecs-bluegreen-rollback.md) restores state from internal rollback data captured by this step and ECS BlueGreen Swap Target Groups, exposed through `${{rollback.data.*}}` expressions, or auto-resolves it when its own fields are left unset.

***

## Next steps

* Go to [ECS BlueGreen Swap Target Groups step](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/step-library/ecs-bluegreen-swap-target-groups.md) for the step that follows in the swap variant.
* Go to [ECS BlueGreen Traffic Shift step](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/step-library/ecs-bluegreen-traffic-shift.md) for the step that follows in the traffic shift variant.
* 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 the swap variant.
* 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.
