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

# ECS Service Setup step

The ECS Service Setup step registers a new task definition revision, creates a new versioned ECS service at zero instances, and captures rollback data for the deployment.

The ECS Service Setup step is the first step in a basic ECS deployment. It registers a new ECS task definition revision, removes stale service versions, creates the new service at zero instances, and captures rollback data. The ECS Upgrade Container step runs next to scale the service to the target count.

**Step Template ID:** `ecsServiceSetupStep`

***

## ECS Service Setup step YAML

```yaml
- name: ECS Service Setup
  id: ecsServiceSetup
  deploy:
    uses: ecsServiceSetupStep
    with:
      new_service: my-service
      resize_strategy: RESIZE_NEW_FIRST
      steady_state_timeout: 5m
      match_running_instances: false
      task_type: task_definition
      task_definition: ${{serviceOutput.manifests.ecsTaskDefinition.paths}}
      service_definition: ${{serviceOutput.manifests.ecsServiceDefinition.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 Service Setup step fields

| Field                                 | YAML key                  | Required | Default            | Description                                                                                                                                                                                           |
| ------------------------------------- | ------------------------- | -------- | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **New Service Name**                  | `new_service`             | Yes      | —                  | The base name for the new ECS service. Harness appends an incrementing suffix (`__N`) to generate the versioned service name.                                                                         |
| **Old Service Name**                  | `old_service`             | No       | —                  | The name of the currently running service. Harness auto-resolves this from the cluster when left empty.                                                                                               |
| **Resize Strategy**                   | `resize_strategy`         | No       | `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 the new one. |
| **Steady State Timeout**              | `steady_state_timeout`    | No       | `5m`               | How long Harness waits for each service to reach steady state before timing out.                                                                                                                      |
| **Same as Already Running Instances** | `match_running_instances` | No       | `false`            | When `true`, Harness matches the new service desired count to the current running instance count of the old service.                                                                                  |

### Service configuration

These fields are derived from the service and artifact configuration. Harness resolves them automatically and you do not need to change them.

| Field                    | YAML key             | Default value                                             | Description                                                                    |
| ------------------------ | -------------------- | --------------------------------------------------------- | ------------------------------------------------------------------------------ |
| **Task Definition Type** | `task_type`          | `task_definition`                                         | The task definition format. Harness reads this from the service manifest type. |
| **Task Definition**      | `task_definition`    | `${{serviceOutput.manifests.ecsTaskDefinition.paths}}`    | Path to the task definition file, resolved from the ECS service manifest.      |
| **Service Definition**   | `service_definition` | `${{serviceOutput.manifests.ecsServiceDefinition.paths}}` | Path to the service definition file, resolved from the ECS 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 Service Setup step works

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

1. Retrieves all ECS services from the cluster that share the base service name prefix, and identifies the current running version and any stale older versions.
2. Registers a new ECS task definition revision from the task definition manifest in the service configuration.
3. Downsizes any stale services (older than the most recent previous version) to zero instances, waits for each to reach steady state, then deletes them.
4. Creates a new versioned service (e.g., `my-service__28`) at zero instances using the new task definition.
5. Captures rollback data after the new service is created: the previous task definition ARN, service configuration, scalable targets, and scaling policies.
6. Emits the new and old service names, their max instance counts, and whether this is the first deployment as step outputs for the ECS Upgrade Container and ECS Basic Rollback steps.

***

## Output variables

The ECS Service Setup step emits the following output variables. The [ECS Upgrade Container step](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/step-library/ecs-upgrade-container.md) and [ECS Basic Rollback step](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/step-library/ecs-basic-rollback.md) reference them using the expression `${{stage.steps.<step-id>.output.outputVariables.<name>}}`, where `<step-id>` is the `id` you set on the ECS Service Setup step.

| Output variable      | Description                                                                                       |
| -------------------- | ------------------------------------------------------------------------------------------------- |
| `newService`         | The name of the new versioned ECS service that this step creates (for example, `my-service__28`). |
| `oldServiceName`     | The name of the previously running ECS service. Empty on a first deployment.                      |
| `newServiceMaxCount` | The maximum instance cap resolved for the new service from its auto-scaling configuration.        |
| `oldServiceMaxCount` | The maximum instance cap resolved for the old service from its auto-scaling configuration.        |
| `isFirstDeployment`  | `true` when there is no previously running service for this base service name, `false` otherwise. |

***

## Next steps

* 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 step that runs after ECS Service Setup in a basic deployment.
* Go to [ECS Basic Rollback step](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/step-library/ecs-basic-rollback.md) for the rollback step that consumes these output variables.
* 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.
