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

# ECS Upgrade Container step

The ECS Upgrade Container step scales the new ECS service to the target instance count, waits for steady state, applies auto-scaling, and optionally downsizes the previous service.

The ECS Upgrade Container step runs after [ECS Service Setup](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/step-library/ecs-service-setup.md) in a basic deployment. It scales the new service from zero to the target instance count, waits for the service to reach steady state, applies auto-scaling configuration, and optionally downsizes the previous service version.

**Step Template ID:** `ecsUpgradeContainerStep`

***

## ECS Upgrade Container step YAML

Scale new service to 100%, keep old service running. **New Service Name** and **Old Service Name** are wired from the [ECS Service Setup step](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/step-library/ecs-service-setup.md) outputs:

```yaml
- name: ECS Upgrade Container
  id: ecsUpgradeContainer
  deploy:
    uses: ecsUpgradeContainerStep
    with:
      new_instances: 100
      new_instance_unit: PERCENTAGE
      new_service: ${{stage.steps.ecsServiceSetup.output.outputVariables.newService}}
      old_service: ${{stage.steps.ecsServiceSetup.output.outputVariables.oldServiceName}}
      resize_strategy: RESIZE_NEW_FIRST
      new_service_max_instances: ${{stage.steps.ecsServiceSetup.output.outputVariables.newServiceMaxCount}}
      old_service_max_instances: ${{stage.steps.ecsServiceSetup.output.outputVariables.oldServiceMaxCount}}
      steady_state_timeout: 5m
      steady_state_check: true
      targets: ${{serviceOutput.manifests.ecsScalableTarget.paths}}
      policies: ${{serviceOutput.manifests.ecsScalingPolicy.paths}}
      scheduled_actions: ${{serviceOutput.manifests.ecsScheduledActions.paths}}
      connector: ${{infra.connectorRef}}
      region: ${{infra.region}}
      cluster: ${{infra.cluster}}
      log_level: info
```

With downsize, scale new service to 100% and downsize old service to 0%:

```yaml
- name: ECS Upgrade Container
  id: ecsUpgradeContainer
  deploy:
    uses: ecsUpgradeContainerStep
    with:
      new_instances: 100
      new_instance_unit: PERCENTAGE
      downsize_old_instance: 0
      downsize_old_instance_unit: PERCENTAGE
      new_service: ${{stage.steps.ecsServiceSetup.output.outputVariables.newService}}
      old_service: ${{stage.steps.ecsServiceSetup.output.outputVariables.oldServiceName}}
      resize_strategy: RESIZE_NEW_FIRST
      new_service_max_instances: ${{stage.steps.ecsServiceSetup.output.outputVariables.newServiceMaxCount}}
      old_service_max_instances: ${{stage.steps.ecsServiceSetup.output.outputVariables.oldServiceMaxCount}}
      steady_state_timeout: 5m
      steady_state_check: true
      targets: ${{serviceOutput.manifests.ecsScalableTarget.paths}}
      policies: ${{serviceOutput.manifests.ecsScalingPolicy.paths}}
      scheduled_actions: ${{serviceOutput.manifests.ecsScheduledActions.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 Upgrade Container step fields

### Instance configuration

| Field                           | YAML key                     | Required | Default      | Description                                                                                                                                               |
| ------------------------------- | ---------------------------- | -------- | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **New Instance Count**          | `new_instances`              | No       | `100`        | The target instance count for the new service after upgrade. The meaning depends on **New Instance Unit**.                                                |
| **New Instance Unit**           | `new_instance_unit`          | No       | `PERCENTAGE` | The unit for **New Instance Count**. `PERCENTAGE` calculates the count as a percentage of **New Service Max Instances**. `COUNT` uses the value directly. |
| **Downsize Old Instance Count** | `downsize_old_instance`      | No       | —            | The desired count for the old service after the new service reaches steady state. Leave empty to keep the old service at its current count.               |
| **Downsize Old Instance Unit**  | `downsize_old_instance_unit` | No       | —            | The unit for **Downsize Old Instance Count**. Required when **Downsize Old Instance Count** is set.                                                       |

### Service names

| Field                | YAML key      | Required | Default | Description                                                                                                 |
| -------------------- | ------------- | -------- | ------- | ----------------------------------------------------------------------------------------------------------- |
| **New Service Name** | `new_service` | Yes      | —       | The name of the new ECS service created by the ECS Service Setup step.                                      |
| **Old Service Name** | `old_service` | No       | —       | The name of the currently running ECS service. Harness auto-resolves this from the cluster when left empty. |

### Resize and scaling

| Field                         | YAML key                    | Default            | Description                                                                                                                                                                               |
| ----------------------------- | --------------------------- | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Resize Strategy**           | `resize_strategy`           | `RESIZE_NEW_FIRST` | The order in which Harness scales services. `RESIZE_NEW_FIRST` scales up the new service before downsizing the old one. `DOWNSIZE_OLD_FIRST` downsizes the old service before scaling up. |
| **New Service Max Instances** | `new_service_max_instances` | `0`                | The maximum instance cap for the new service. Set to `0` to derive the cap from auto-scaling configuration.                                                                               |
| **Old Service Max Instances** | `old_service_max_instances` | `0`                | The maximum instance cap for the old service. Set to `0` to derive the cap from auto-scaling configuration.                                                                               |
| **Steady State Timeout**      | `steady_state_timeout`      | `5m`               | How long Harness waits for the service to reach steady state before timing out.                                                                                                           |
| **Steady State Check**        | `steady_state_check`        | `true`             | When `true`, Harness waits for the new service to reach steady state before proceeding.                                                                                                   |

### Auto-scaling configuration

These fields resolve the scalable targets, scaling policies, and scheduled actions to apply to the new service after it reaches steady state. They are auto-resolved from the service manifests and do not need to be changed.

| Field                 | YAML key            | Default value                                            | Description                                                                                                            |
| --------------------- | ------------------- | -------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| **Scalable Targets**  | `targets`           | `${{serviceOutput.manifests.ecsScalableTarget.paths}}`   | Path to the scalable target definition file. Resolved from the ECS Scalable Target Definition manifest in the service. |
| **Scaling Policies**  | `policies`          | `${{serviceOutput.manifests.ecsScalingPolicy.paths}}`    | Path to the scaling policy definition file. Resolved from the ECS Scaling Policy Definition manifest in the service.   |
| **Scheduled Actions** | `scheduled_actions` | `${{serviceOutput.manifests.ecsScheduledActions.paths}}` | Path to the scheduled actions definition file. Resolved from the service manifest.                                     |

### 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. |

### Other configuration

| Field         | YAML key    | Default | Description                                                               |
| ------------- | ----------- | ------- | ------------------------------------------------------------------------- |
| **Log Level** | `log_level` | `info`  | Log verbosity for the step execution. Set to `debug` for detailed output. |

***

## How the ECS Upgrade Container step works

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

1. Retrieves all ECS services from the cluster and identifies the new service and the old (currently running) service.
2. Determines whether this is a first-time deployment (no running old service) or a subsequent deployment.
3. Executes the resize strategy: with `RESIZE_NEW_FIRST`, Harness scales the new service first; with `DOWNSIZE_OLD_FIRST`, it downsizes the old service before scaling up the new one.
4. Scales the new service to the target instance count and waits for it to reach steady state.
5. After the new service is stable, registers scalable targets and scaling policies on the new service using the paths from the service manifests.
6. Removes stale scaling policies and scalable targets from the old service.
7. If **Downsize Old Instance Count** is set, scales the old service down to the specified count.
8. Collects running task data from both services for the Harness deployment dashboard.

***

## Next steps

* Go to [ECS Service Setup step](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/step-library/ecs-service-setup.md) for the step that runs before ECS Upgrade Container in a basic deployment.
* 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.
