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

# ECS services

Configure an ECS service with a task definition, service definition, scaling configuration, and artifact source for Harness CD deployments.

An ECS service in Harness holds the task definition, service definition, optional scaling configuration, and artifact source for your deployment. Configure it once and reuse it across stages and pipelines.

***

## What you will learn from this topic

* How to configure an ECS service with a task definition, service definition, and artifact source.
* How to add optional scaling configuration including scalable targets, scaling policies, config files, and variables.

***

## Before you begin

* An AWS account with an ECS cluster. Go to [ECS infrastructure](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/ecs-infrastructure.md) to connect it.
* A container image pushed to a supported registry such as Amazon ECR or Docker Hub.

***

## Create an ECS service

1. Go to **Services** and click **New Service**.
2. Enter a service name. Under **Storage**, select **Inline** or a Git repository. Click **Save**.
3. Set **Task Definition Type** to **Task Definition**.
4. Under **Task Definition**, click **Add** and select your manifest source to add the task definition file.
5. Under **Service Definition**, click **Add** and select your manifest source to add the service definition file.
6. Under **Artifacts**, click **Add** next to **Primary** and select your artifact source type.

The following top-level fields are available when creating an ECS service:

| Field                    | Required | Description                                                                                           |
| ------------------------ | -------- | ----------------------------------------------------------------------------------------------------- |
| **Name**                 | Yes      | Display name for the service. Harness auto-generates the **Id** from the name.                        |
| **Task Definition Type** | Yes      | The format of the task definition. Select **Task Definition** to provide a full task definition YAML. |

***

## Add a task definition

A task definition is a YAML file that describes the container configuration for your ECS task. Add it as a manifest with **Type** set to **Task Definition**.

The following fields are available in the **Add Manifest** dialog:

| Field                | Required                | Description                                                                                                                |
| -------------------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| **Type**             | Yes                     | Set to **Task Definition**.                                                                                                |
| **Source**           | Yes                     | The source where the manifest file is stored. Supports Harness Code, GitHub, Git, GitLab, Bitbucket, and Azure Repos.      |
| **ID**               | Yes                     | A unique identifier for this manifest within the service.                                                                  |
| **Repository**       | Yes                     | The repository that contains the task definition file.                                                                     |
| **Fetch**            | Yes                     | How Harness resolves the file version. Select **Branch** to fetch from a branch, or **Commit** to fetch a specific commit. |
| **Branch**           | Yes (if Fetch = Branch) | The branch to fetch the file from.                                                                                         |
| **File/Folder Path** | Yes                     | Path to the task definition YAML file in the repository. For example, `ecs/task-definition.yaml`.                          |

***

## Add a service definition

A service definition is a YAML file that describes the ECS service configuration, including desired count, deployment configuration, and network settings. Add it as a manifest with **Type** set to **ECS Service Definition**.

The following fields are available in the **Add Manifest** dialog:

| Field                | Required                | Description                                                                                                                |
| -------------------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| **Type**             | Yes                     | Set to **ECS Service Definition**.                                                                                         |
| **Source**           | Yes                     | The source where the manifest file is stored. Supports Harness Code, GitHub, Git, GitLab, Bitbucket, and Azure Repos.      |
| **ID**               | Yes                     | A unique identifier for this manifest within the service.                                                                  |
| **Git Connector**    | Yes                     | The Git connector used to fetch the service definition file.                                                               |
| **Fetch**            | Yes                     | How Harness resolves the file version. Select **Branch** to fetch from a branch, or **Commit** to fetch a specific commit. |
| **Branch**           | Yes (if Fetch = Branch) | The branch to fetch the file from.                                                                                         |
| **File/Folder Path** | Yes                     | Path to the service definition YAML file in the repository. For example, `CreateServiceRequest.yaml`.                      |

***

## Add an artifact source

An artifact source tells Harness where to pull the container image for the deployment. The following artifact source types are supported:

* **Amazon ECR**
* **Docker Registry**
* **Nexus 3 Registry**
* **Artifactory Registry**
* **Azure Container Registry**
* **Custom Artifact**

A **Primary** artifact is required. You can add additional **Sidecar** artifacts for multi-container tasks.

During the service step, Harness fetches artifact metadata (type, image path, tag, digest, registry hostname) from the artifact registry and writes it to the step output. Harness does not pull the container image at this stage. The ECS task definition references the image URI, and ECS pulls the image at runtime.

{% tabs %}
{% tab title="Amazon ECR" %}

| Field           | Required | Description                                                                                                                                               |
| --------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **ID**          | Yes      | A unique identifier for this artifact source within the service. Defaults to `artifact` for the primary source.                                           |
| **Connector**   | Yes      | An AWS connector with access to the ECR registry.                                                                                                         |
| **Region**      | Yes      | The AWS region where the ECR registry is hosted. For example, `us-east-1`.                                                                                |
| **Registry ID** | No       | The AWS account ID that owns the ECR registry. Required only for cross-account ECR access.                                                                |
| **Image path**  | Yes      | The ECR repository name. For example, `todolist`.                                                                                                         |
| **Tag**         | Yes      | The image tag to deploy. Supports fixed value, expression, or runtime input.                                                                              |
| **Tag regex**   | No       | A regular expression to match the image tag at runtime. Use this instead of **Tag** when you want Harness to resolve the latest matching tag dynamically. |
| **Digest**      | No       | The image digest to deploy. Use this to pin to a specific image by digest instead of tag.                                                                 |
| {% endtab %}    |          |                                                                                                                                                           |

{% tab title="Docker Registry" %}

| Field          | Required | Description                                                                                                                       |
| -------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------- |
| **ID**         | Yes      | A unique identifier for this artifact source within the service.                                                                  |
| **Connector**  | Yes      | A Docker Registry connector pointing to Docker Hub or a private Docker registry.                                                  |
| **Image path** | Yes      | The full repository path. For Docker Hub public images, use `library/nginx`. For private repositories, use `<namespace>/<image>`. |
| **Tag**        | Yes      | The image tag to deploy. Supports fixed value, expression, or runtime input.                                                      |
| **Digest**     | No       | The image digest to deploy. Use this to pin to a specific image by digest instead of tag.                                         |
| {% endtab %}   |          |                                                                                                                                   |

{% tab title="Nexus 3 Registry" %}

| Field              | Required | Description                                                      |
| ------------------ | -------- | ---------------------------------------------------------------- |
| **ID**             | Yes      | A unique identifier for this artifact source within the service. |
| **Connector**      | Yes      | A Nexus connector with access to the repository.                 |
| **Repository URL** | Yes      | The base URL of the Nexus repository.                            |
| **Repository**     | Yes      | The name of the Nexus repository.                                |
| **Artifact path**  | Yes      | The path to the artifact within the repository.                  |
| **Tag**            | Yes      | The artifact tag or version to deploy.                           |
| {% endtab %}       |          |                                                                  |

{% tab title="Artifactory Registry" %}

| Field             | Required | Description                                                      |
| ----------------- | -------- | ---------------------------------------------------------------- |
| **ID**            | Yes      | A unique identifier for this artifact source within the service. |
| **Connector**     | Yes      | An Artifactory connector with access to the repository.          |
| **Repository**    | Yes      | The name of the Artifactory Docker repository.                   |
| **Artifact path** | Yes      | The image path within the repository.                            |
| **Tag**           | Yes      | The image tag to deploy.                                         |
| {% endtab %}      |          |                                                                  |

{% tab title="Azure Container Registry" %}

| Field               | Required | Description                                                      |
| ------------------- | -------- | ---------------------------------------------------------------- |
| **ID**              | Yes      | A unique identifier for this artifact source within the service. |
| **Connector**       | Yes      | An Azure connector with access to the registry.                  |
| **Subscription ID** | Yes      | The Azure subscription ID that owns the registry.                |
| **Registry**        | Yes      | The ACR registry name.                                           |
| **Repository**      | Yes      | The repository (image name) within the registry.                 |
| **Tag**             | Yes      | The image tag to deploy.                                         |
| **Digest**          | No       | The image digest to deploy.                                      |
| {% endtab %}        |          |                                                                  |

{% tab title="Custom Artifact" %}

| Field                    | Required | Description                                                                         |
| ------------------------ | -------- | ----------------------------------------------------------------------------------- |
| **ID**                   | Yes      | A unique identifier for this artifact source within the service.                    |
| **Script**               | Yes      | A shell script that fetches artifact metadata and outputs it as JSON.               |
| **Version**              | Yes      | The artifact version to deploy. Supports fixed value, expression, or runtime input. |
| **Artifacts array path** | No       | The JSON path to the array of artifact versions returned by the script.             |
| **Version path**         | No       | The JSON path to the version field within each item in the artifacts array.         |
| {% endtab %}             |          |                                                                                     |
| {% endtabs %}            |          |                                                                                     |

***

## Advanced

The **Advanced** section on the service holds optional auto-scaling manifests, config files, and variables.

### Scalable target

A scalable target defines the Application Auto Scaling resource attached to the ECS service. Add it as a manifest with **Type** set to **ECS Scalable Target Definition**. This manifest is optional. Add it only if your ECS service uses Application Auto Scaling.

The fields are the same as the task definition manifest. Set **Type** to **ECS Scalable Target Definition** and point **File/Folder Path** to your scalable target JSON or YAML file.

During deployment, Harness fetches the scalable target configuration from the manifest and registers it with the service. During rollback, Harness restores the previous scalable target state.

{% hint style="info" %}
**Remove autoscaling permissions if unused**

If you do not use scalable targets, you can remove the `application-autoscaling:DescribeScalableTargets` permission from your AWS connector's IAM policy. Go to [ECS infrastructure](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/ecs-infrastructure.md) for the full permissions list.
{% endhint %}

### Scaling policy

A scaling policy defines the rules that Application Auto Scaling uses to scale your ECS service. Add it as a manifest with **Type** set to **ECS Scaling Policy Definition**. This manifest is optional. Add it only if your ECS service uses scaling policies.

The fields are the same as the task definition manifest. Set **Type** to **ECS Scaling Policy Definition** and point **File/Folder Path** to your scaling policy JSON or YAML file.

During deployment, Harness fetches the scaling policy from the manifest and applies it to the service. During rollback, Harness restores the previous scaling policy state.

### Config files

Config files attach additional files, such as application configuration or environment files, to the service without including them in the task definition manifest.

The following fields are available in the **Add Config File** dialog:

| Field                | Required                | Description                                                                                                                |
| -------------------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| **Source**           | Yes                     | The source where the config file is stored. Supports Harness Code, GitHub, Git, GitLab, Bitbucket, and Azure Repos.        |
| **ID**               | Yes                     | A unique identifier for this config file within the service.                                                               |
| **GitHub Connector** | Yes                     | The GitHub connector used to fetch the config file.                                                                        |
| **Repository**       | Yes                     | The repository that contains the config file.                                                                              |
| **Fetch**            | Yes                     | How Harness resolves the file version. Select **Branch** to fetch from a branch, or **Commit** to fetch a specific commit. |
| **Branch**           | Yes (if Fetch = Branch) | The branch to fetch the file from.                                                                                         |
| **File Path**        | Yes                     | Path to the config file in the repository.                                                                                 |

### Variables

Variables let you define service-scoped values that you can reference from pipeline stages using this service.

The following fields are available in the **New Variable** dialog:

| Field                                       | Required | Description                                                                                                                     |
| ------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------- |
| **Type**                                    | Yes      | The variable type. For example, **String**.                                                                                     |
| **Name**                                    | Yes      | The variable name.                                                                                                              |
| **Value**                                   | No       | The variable value.                                                                                                             |
| **Set variable as required during runtime** | No       | When enabled, Harness prompts for this variable's value at pipeline runtime instead of using a fixed value. Default is `False`. |
| **Description**                             | No       | A description of the variable's purpose.                                                                                        |

***

## Metadata

The service also has a **Metadata** section for tagging and labeling the service resource within Harness. These fields do not affect the ECS deployment itself.

***

## Next steps

* Go to [ECS infrastructure](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/ecs-infrastructure.md) to configure an infrastructure definition.
* Go to [Deployment strategies](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/ecs-deployment-strategies.md) to configure a deployment strategy.
