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

# ECS Basic Rollback step

The ECS Basic Rollback step restores the previous ECS service and task definition, or scales the new service to zero on a first deployment, when a basic deployment fails.

The ECS Basic Rollback step runs when a basic deployment stage fails after the [ECS Service Setup step](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/step-library/ecs-service-setup.md) has executed. It uses the rollback data that ECS Service Setup captured to restore the previous service, or to clean up the new service if there was no previous version to restore.

**Step Template ID:** `ecsBasicRollbackStep`

***

## ECS Basic Rollback step YAML

```yaml
- name: ECS Basic Rollback
  id: ecsBasicRollback
  template:
    uses: ecsBasicRollbackStep
    with:
      new_service: ${{stage.steps.ecsServiceSetup.output.outputVariables.newService}}
      first_deployment: ${{stage.steps.ecsServiceSetup.output.outputVariables.isFirstDeployment}}
```

***

## 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 Basic Rollback step fields

These fields identify the new service to clean up on a first deployment and whether a previous version exists. Both are wired from the ECS Service Setup step outputs and do not need to be changed. The previous service to restore on subsequent deployments is resolved internally from rollback data captured by ECS Service Setup, not from a wired field.

| Field                | YAML key           | Default | Description                                                                                                                                                                                                                                |
| -------------------- | ------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **New Service**      | `new_service`      | —       | The name of the new service that ECS Service Setup created. Used to identify which service to scale down on a first deployment, when there is no previous service to restore. Wired from the ECS Service Setup step's `newService` output. |
| **First Deployment** | `first_deployment` | —       | Whether this is a first deployment with no previous service to restore. Wired from the ECS Service Setup step's `isFirstDeployment` output.                                                                                                |
| **Log Level**        | `log_level`        | `info`  | Log verbosity for the step execution.                                                                                                                                                                                                      |

***

## How the ECS Basic Rollback step works

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

1. Reads the **New Service** name and **First Deployment** flag from the ECS Service Setup step outputs.
2. Checks whether this is a first deployment or a subsequent deployment.
3. Restores or cleans up services according to the deployment history.
4. Collects running task data from the restored or cleaned-up services for the Harness deployment dashboard.

Rollback behavior differs by deployment history:

* **First deployment:** There is no previous service to restore. Harness scales the new service that ECS Service Setup created down to zero instances.
* **Subsequent deployments:** Harness restores the previous task definition, scaling policies, and scalable targets on the old service, scales it back to its original instance count, and deletes the new service that ECS Service Setup created.

***

## 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 captures the rollback data used here.
* Go to [ECS Upgrade Container step](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/step-library/ecs-upgrade-container.md) for the deploy step paired with this rollback.
* 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.
