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

# ECS infrastructure

Configure an ECS infrastructure definition to connect Harness to an AWS ECS cluster for deployments.

An infrastructure definition connects Harness to the AWS ECS cluster where your services are deployed. Each definition is scoped to an environment and specifies the AWS connector, region, and cluster.

***

## What you will learn from this topic

* How to create a Harness environment and an ECS infrastructure definition that targets an AWS ECS cluster.
* How to configure AWS authentication and the IAM permissions Harness needs to deploy to ECS.

***

## Before you begin

* **An AWS connector:** The connector must use credentials that have the IAM permissions listed in [IAM permissions](#iam-permissions) below.
* **An ECS cluster:** The cluster must be running in a supported AWS region.

***

## Create an environment

1. Go to **Deployments**, expand the drop-down, and select **Environments**.
2. Select **+ New Environment**.
3. Enter a name and select an environment type: **Pre-Production** or **Production**. The type affects governance policies and deployment dashboards.
4. Select **Save**.

Harness opens the environment detail page with two tabs: **Configuration** and **Infrastructure Definitions**.

***

## Create an infrastructure definition

Infrastructure definitions live inside an environment. Each definition links the environment to a specific AWS ECS cluster.

1. Open the environment and select the **Infrastructure Definitions** tab.
2. Select **+ Create Infrastructure**.
3. In the dialog, select **Amazon ECS** as the deployment target.
4. Enter a name. Harness auto-suggests one, and you can change both the name and ID.
5. Under **Storage**, choose **Inline** or a Git repository.
6. Fill in the **Cluster Details** fields as described below.
7. Select **Save**.

### Top-level fields

| Field       | Description                                                                                                                              |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| **Name**    | Display name for the infrastructure definition. Harness auto-generates the **Id** from the name.                                         |
| **Storage** | Where the infrastructure definition is stored. Select **Inline** to store it in Harness, or select a Git repository to store it as code. |

### Cluster details

The cluster details section specifies which AWS account and cluster Harness deploys to.

| Field         | Required | Description                                                                                                                                       |
| ------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Connector** | Yes      | An AWS connector configured with credentials that have the required IAM permissions. Go to [IAM permissions](#iam-permissions) for the full list. |
| **Region**    | Yes      | The AWS region where the target ECS cluster runs. For example, `us-east-1`. Harness uses this to populate the **Cluster** dropdown.               |
| **Cluster**   | Yes      | The ECS cluster to deploy to. Harness populates the dropdown from the clusters available in the selected region. Supports expressions.            |

### Simultaneous deployments

| Field                        | Default | Description                                                                                                                                                                         |
| ---------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Simultaneous deployments** | `False` | By default, Harness queues deployments to the same infrastructure to avoid conflicts. Set to `True` to allow multiple deployments to run against the same cluster at the same time. |

### Scope to specific services

The **Scope to Specific Services** section restricts which Harness services can use this infrastructure definition. By default, the definition is available to all services in the environment. Add specific services to limit access.

***

## Authentication

The AWS connector supports the following credential types for authenticating with AWS.

### AWS access key

Use an IAM user's access key ID and secret access key. Go to [AWS Connector settings reference](https://github.com/harness/harness-developer-hub/tree/main/3k-docs/platform/harness-platform-resources/connectors/cloud-providers/ref-cloud-providers/aws-connector-settings-reference.md) to configure the connector.

1. In AWS IAM, create or edit an IAM user and attach the custom managed policy described in [IAM permissions](#iam-permissions) below.
2. Generate an access key for the IAM user under **Security credentials** in the IAM console.
3. Use the access key ID and secret access key when configuring the Harness AWS connector.

### OIDC

If you use the OIDC credential type, add a trust relationship between the IAM role and your identity provider to configure OIDC with AWS in Harness.

***

## IAM permissions

Create a custom managed IAM policy and attach it to the IAM user or role used by the Harness AWS connector. The policy must include the following permissions.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ecr:DescribeRepositories",
        "ecs:ListClusters",
        "ecs:ListServices",
        "ecs:DescribeServices",
        "ecr:ListImages",
        "ecr:DescribeImages",
        "ecs:RegisterTaskDefinition",
        "ecs:CreateService",
        "ecs:ListTasks",
        "ecs:DescribeTasks",
        "ecs:DeleteService",
        "ecs:UpdateService",
        "ecs:DescribeContainerInstances",
        "ecs:DescribeTaskDefinition",
        "application-autoscaling:DescribeScalableTargets",
        "application-autoscaling:DescribeScalingPolicies",
        "application-autoscaling:PutScheduledAction",
        "application-autoscaling:DescribeScheduledActions",
        "application-autoscaling:DeleteScheduledAction",
        "iam:ListRoles",
        "iam:PassRole"
      ],
      "Resource": "*"
    }
  ]
}
```

The following table describes what each permission is used for:

| Permission                                         | Purpose                                                                                                    |
| -------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `ecr:DescribeRepositories`                         | Lists ECR repositories so Harness can fetch image details for the task definition.                         |
| `ecs:ListClusters`                                 | Lists ECS clusters in a region for the infrastructure definition dropdown and for instance sync.           |
| `ecs:ListServices`                                 | Lists services deployed in the cluster so Harness can identify the deployed service.                       |
| `ecs:DescribeServices`                             | Gets service details to check steady state after deployment.                                               |
| `ecr:ListImages`                                   | Lists images from the selected ECR repository during artifact selection.                                   |
| `ecr:DescribeImages`                               | Describes ECR images to fetch tag details for the task definition.                                         |
| `ecs:RegisterTaskDefinition`                       | Creates a new task definition revision during deployment.                                                  |
| `ecs:CreateService`                                | Creates an ECS service definition.                                                                         |
| `ecs:ListTasks`                                    | Lists deployed tasks and captures the revision.                                                            |
| `ecs:DescribeTasks`                                | Describes tasks running on the cluster.                                                                    |
| `ecs:DeleteService`                                | Deletes the older service version when Harness deploys a new one.                                          |
| `ecs:UpdateService`                                | Updates an existing ECS service and configures a new revision.                                             |
| `ecs:DescribeContainerInstances`                   | Surfaces container image information on the Harness Service Dashboard.                                     |
| `ecs:DescribeTaskDefinition`                       | Describes the deployed task definition and collects revision data for rollback.                            |
| `application-autoscaling:DescribeScalableTargets`  | Describes scalable targets deployed with the ECS service. Remove if you do not use scalable targets.       |
| `application-autoscaling:DescribeScalingPolicies`  | Describes scaling policies on the deployed service. Remove if you do not use scaling policies.             |
| `application-autoscaling:PutScheduledAction`       | Creates or updates a scheduled action on the deployed service. Remove if you do not use scheduled actions. |
| `application-autoscaling:DescribeScheduledActions` | Describes scheduled actions to capture rollback data. Remove if you do not use scheduled actions.          |
| `application-autoscaling:DeleteScheduledAction`    | Deletes scheduled actions during redeployment or rollback. Remove if you do not use scheduled actions.     |
| `iam:ListRoles`                                    | Lists IAM roles. Harness uses the role associated with the connector for deployment.                       |
| `iam:PassRole`                                     | Passes the IAM role with the ECS deployment.                                                               |

{% hint style="info" %}
**Simplify with a managed policy**

If you prefer not to manage a custom policy, you can attach the AWS-managed `AmazonECS_FullAccess` policy instead. Go to [Amazon ECS full access](https://docs.amazonaws.cn/en_us/AmazonECS/latest/developerguide/security-iam-awsmanpol.html) on the AWS documentation for details.
{% endhint %}

***

## Next steps

* 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.
* Go to [ECS services](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/ecs-services.md) to configure a service.
