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

# Deploy a Docker Image to Amazon ECS

Deploy a Docker image to Amazon ECS using a Harness Continuous Delivery pipeline.

{% hint style="info" %}
[Sign up for Harness CD](https://app.harness.io/auth/#/signup/?module=cd\&utm_source=website\&utm_medium=harness-developer-hub\&utm_campaign=cd-plg\&utm_content=tutorials-cd-kubernetes-manifest).
{% endhint %}

[Amazon Elastic Container Service](https://aws.amazon.com/ecs/) is an AWS offering for running containerized workloads. Define an ECS [task definition](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definitions.html) describing your workload and a [service definition](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service_definition_parameters.html) describing where you want to run your workload, and you are ready to deploy. A Continuous Delivery (CD) pipeline is a good place to orchestrate a deployment to Amazon ECS. This tutorial walks through deploying an image with Amazon ECS inside a Harness CD pipeline.

![A high-level overview of deploying a Docker image to Amazon ECS using a Harness CD pipeline](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-8ba5a41c561458c76bef64ab3547d80c3cf79a89%2Foverview.png?alt=media)

There are a few AWS items to set up, such as the ECS cluster itself, which this tutorial walks through configuring. If you have not signed up for Harness CD, sign up before you begin.

## What you will learn from this topic

* How to set up the required AWS IAM roles, policies, VPC, and ECS cluster for a Harness deployment
* How to install a Harness Delegate in your AWS environment and connect Harness to AWS
* How to create a Harness ECS service, environment, and CD pipeline
* How to run the pipeline and verify a successful deployment to Amazon ECS

## Before you begin

Confirm the following before you start this tutorial:

* **AWS account**: You need access to an [AWS account](https://aws.amazon.com/console/) to create the IAM roles, policies, VPC, and ECS cluster this tutorial uses.
* **Harness account with CD enabled**: If you do not have a Harness account, [sign up for a Harness account](https://app.harness.io/auth/#/signup/?module=cd&?utm_source=website\&utm_medium=harness-developer-hub\&utm_campaign=cd-plg\&utm_content=get-started) for access to the Continuous Delivery module. A default [Harness project](https://developer.harness.io/docs/platform/overview#organizations-and-projects) is created for you automatically, and it is sufficient for this tutorial.
* **Delegate installation target**: You need a Kubernetes cluster or a host with the Docker runtime to install the Harness Delegate that connects Harness to your AWS account. This tutorial covers Kubernetes (Helm chart, Terraform, or a Kubernetes manifest) and Docker installation paths.

***

## Set up the Amazon ECS cluster

Amazon ECS creates EC2 instances on your behalf to run your workloads, so if you have used EC2 in the past, some of these items will not be unfamiliar. You can create the following items individually or use the AWS ECS Cluster Creation Wizard to create them for you.

**ECS instance role (IAM)**

The ECS instance role allows the running containers to call underlying ECS API commands. If you do not have an `ecsInstanceRole`, AWS provides [documentation to create one](https://docs.aws.amazon.com/batch/latest/userguide/instance_IAM_role.html). Set up the trust relationships per the AWS documentation so your user can assume the role.

![The ECS instance role configuration in the AWS IAM console](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-7763bc9f4760da54af1c8f818ca5368d264f6ab9%2Fecsinstance-role.png?alt=media)

**ECS managed policy (IAM)**

Next, choose or set up a managed policy that allows Harness to call ECS. As an example, and not a Harness-specific managed policy, you can use the generic [AmazonECS\_FullAccess](https://docs.aws.amazon.com/AmazonECS/latest/userguide/security-iam-awsmanpol.html) policy. Do not use this broad policy in production.

![The AmazonECS\_FullAccess policy in the AWS IAM console](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-7442408e61df38543cd6e0c2dcb1fd0f60658bb2%2Fecs-full-access.png?alt=media)

**Attach the managed policy to your IAM user**

Attach the ECS managed policy (**Add permission**) to the IAM user that you will have Harness connect to AWS with.

![Attaching a managed policy to an IAM user in the AWS console](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-462ab974bdfbd0614862ea3b993c98cf57baa4aa%2Fattach-policy.png?alt=media)

**VPC, subnets, and security group**

If this is your first time using ECS, or you have a sandbox account, using the AWS default VPC and its subnets (one for each availability zone in a Region) is fine. Depending on your traffic, create a [security group](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html) to allow that traffic in. This example handles traffic over TCP port 80 with an example image. For the ECS service definition steps later in this tutorial, keep the subnet and security group IDs handy.

### Create the ECS cluster

With the items above created or validated, you are ready to create an ECS cluster. You can pick your flavor of ECS. This example deploys to EC2 Linux + Networking.

Go to **AWS Console** -> **ECS** -> **Clusters** -> **Create Cluster**.

![The Create Cluster wizard in the AWS ECS console](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-3201335b1cec1489a72dd6055e6975bfeb1f1e36%2Fcreate-cluster.png?alt=media)

When filling out the wizard, use the following details:

* **Cluster name**: `harness-ecs`
* **Instance type**: a medium instance type, for example `m5-medium`
* **VPC**: an existing VPC, for example your default VPC
* **Subnets**: select the subnets in your VPC. Regions can sometimes have networking exhaustion, so select multiple subnets that represent each availability zone.
* **Security group**: the security group that was created earlier, or one that can handle inbound TCP 80. You will need to reference the security group ID later, so creating one ahead of time makes the ID visible in the UI to reference.

Once set up, you have an ECS cluster that is ready to accept a workload.

![An ECS cluster in the ready state in the AWS console](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-205d46981ee4474574a720f44952a1635a8fdd94%2Fecs-ready.png?alt=media)

With the cluster ready, you are ready to connect Harness so it can deploy on your behalf.

***

## Set up Harness

### Create your first pipeline project

A default [Harness project](https://developer.harness.io/docs/platform/overview#organizations-and-projects) is created for you automatically when you sign up. Projects are logical groupings of resources, and the generated default project is sufficient for a first-time deployment.

When you navigate back to **Deployments**, set the project context to the default project by clicking the blue chevrons (**>>**) and selecting **Default Project**.

![Selecting the Default Project from the project context switcher](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-20a9f62d75e499d36e45cf684c2ebbd852d4845e%2Fdefault-project.png?alt=media)

With the default project selected, click **Overview** to open a wizard for creating your first pipeline.

![The wizard for creating your first pipeline in the Default Project](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-2ea27c153102977ddbba3a8aeb07729681142200%2Ffirst-pipeline.png?alt=media)

A few Harness entities need to be created before you can deploy: a Harness Delegate and an AWS connector for your user credentials.

### Install a delegate

If you do not have a delegate installed, follow the steps below to install one in either Docker or Kubernetes.

<details>

<summary>Install Delegate</summary>

The [Harness Delegate](https://developer.harness.io/docs/platform/delegates/delegate/delegate-concepts/delegate-overview) is a lightweight worker process that is installed on your infrastructure and communicates only through outbound HTTP/HTTPS to the Harness Platform. This allows the Harness Platform to use the delegate to execute CD and other tasks on your behalf, without any of your secrets leaving your network.

You can install the Harness Delegate on either Docker or Kubernetes.

### Install the default Harness delegate

### Create a new delegate token

You can install delegates from the account, project, or org scope. In this example, create a new token in the account scope.

Perform the following steps to create a new delegate token:

1. In Harness, select **Account Settings**, then select **Account Resources**. The Account Resources page opens.
2. Select **Delegates**. The Delegates list page opens.
3. Select the **Tokens** tab, then select **+New Token**. The **New Token** dialog opens.
4. Enter a token name, for example `firstdeltoken`.
5. Select **Apply**. Harness generates a new token for you.
6. Select **Copy** to copy and store the token in a temporary file.

   You provide this token as an input parameter in the next installation step. The delegate uses this token to authenticate with the Harness Platform.

### Get your Harness account ID

Along with the delegate token, you also need to provide your Harness `accountId` as an input parameter during delegate installation. This `accountId` is present in every Harness URL. For example, in the following URL:

```
https://app.harness.io/ng/#/account/6_vVHzo9Qeu9fXvj-AcQCb/settings/overview
```

`6_vVHzo9Qeu9fXvj-AcQCb` is the `accountId`.

{% hint style="info" %}
**Fields are prefilled when you install from the UI**

When you install a delegate using the Harness UI, several dependencies in this topic are prefilled for your convenience. This topic explains where to find the required information for CLI-based installation.
{% endhint %}

Go to [View account info and subscribe to downtime alerts](https://developer.harness.io/docs/platform/subscriptions-and-licenses/view-account-info-and-subscribe-to-alerts) to locate your account hosting details.

**Prerequisite**

Ensure that you have access to a Kubernetes cluster. For the purposes of this tutorial, this uses minikube.

**Install minikube**

On Windows:

```bash
choco install minikube
```

For Chocolatey installation instructions, go to Installing Chocolatey in the Chocolatey documentation. For additional options to install minikube on Windows, go to minikube start in the minikube documentation.

On macOS:

```bash
brew install minikube
```

For Homebrew installation instructions, go to Installation in the Homebrew documentation.

Now start minikube with the following config.

```bash
minikube start --memory 4g --cpus 4
```

Validate that you have `kubectl` access to your cluster.

```bash
kubectl get pods -A
```

With a Kubernetes cluster available, install the delegate using any of the options below.

**Install the Helm chart**

As a prerequisite, you must have Helm v3 installed on the machine from which you connect to your Kubernetes cluster.

You can now install the delegate using the delegate Helm chart. First, add the `harness-delegate` Helm chart repo to your local Helm registry.

```bash
helm repo add harness-delegate https://app.harness.io/storage/harness-download/delegate-helm-chart/
helm repo update
helm search repo harness-delegate
```

This tutorial uses the `harness-delegate/harness-delegate-ng` chart.

```
NAME                                	CHART VERSION	APP VERSION	DESCRIPTION
harness-delegate/harness-delegate-ng	1.0.8        	1.16.0     	A Helm chart for deploying harness-delegate
```

Now you are ready to install the delegate. The following example installs or upgrades the `firstk8sdel` delegate (a Kubernetes workload) in the `harness-delegate-ng` namespace using the `harness-delegate/harness-delegate-ng` Helm chart.

You can install delegates from the account, project, or org scope. In this example, install a delegate in the account scope.

Perform the following steps to install a delegate:

1. In Harness, select **Account Settings**, then select **Account Resources**. The Account Resources page opens.
2. Select **Delegates**. The Delegates list page opens.
3. Select **New Delegate**. The New Delegate dialog opens.
4. Under **Select where you want to install your Delegate**, select **Kubernetes**.
5. Under **Install your Delegate**, select **Helm Chart**.
6. Copy the Helm upgrade command.

The command uses the default `values.yaml` file located in the delegate Helm chart GitHub repo. To make persistent changes to one or more values, download and update the `values.yaml` file according to your requirements. Once you have updated the file, use it by running the upgrade command below.

```bash
helm upgrade -i firstk8sdel --namespace harness-delegate-ng --create-namespace \
  harness-delegate/harness-delegate-ng \
  -f values.yaml \
  --set delegateName=firstk8sdel \
  --set accountId=PUT_YOUR_HARNESS_ACCOUNTID_HERE \
  --set delegateToken=PUT_YOUR_DELEGATE_TOKEN_HERE \
  --set managerEndpoint=PUT_YOUR_MANAGER_HOST_AND_PORT_HERE \
  --set delegateDockerImage=harness/delegate:yy.mm.verno \
  --set replicas=1 --set upgrader.enabled=true
```

{% hint style="info" %}
**Air-gapped environments need a certificate**

To install a Helm delegate for Harness Self-Managed Enterprise Edition in an air-gapped environment, you must pass your certificate when you add the Helm repo.

```bash
helm repo add harness-delegate --ca-file <.PEM_FILE_PATH> <HELM_CHART_URL_FROM_UI>
```

Go to Install in an air-gapped environment to review requirements for air-gapped environments.
{% endhint %}

Run the command.

**Create main.tf file**

Harness uses a Terraform module for the Kubernetes delegate. This module uses the standard Terraform Helm provider to install the Helm chart onto a Kubernetes cluster whose config, by default, is stored on the same machine at the `~/.kube/config` path. Copy the following into a `main.tf` file stored on a machine from which you want to install your delegate.

```hcl
module "delegate" {
  source = "harness/harness-delegate/kubernetes"
  version = "0.1.8"
  account_id = "PUT_YOUR_HARNESS_ACCOUNTID_HERE"
  delegate_token = "PUT_YOUR_DELEGATE_TOKEN_HERE"
  delegate_name = "firstk8sdel"
  namespace = "harness-delegate-ng"
  manager_endpoint = "PUT_YOUR_MANAGER_HOST_AND_PORT_HERE"
  delegate_image = "harness/delegate:yy.mm.verno"
  replicas = 1
  upgrader_enabled = false
  # Additional optional values to pass to the helm chart
  values = yamlencode({
    javaOpts: "-Xms64M"
  })
}

provider "helm" {
  kubernetes {
    config_path = "~/.kube/config"
  }
}
```

Now replace the variables in the file with your Harness account ID and delegate token values. Replace `PUT_YOUR_MANAGER_HOST_AND_PORT_HERE` with the Harness Manager Endpoint noted below. For Harness SaaS accounts, you can find your Harness Cluster Location on the Account Overview page under the Account Settings section of the left navigation.

**Run Terraform init, plan, and apply**

Initialize Terraform. This downloads the Terraform Helm provider to your machine.

```bash
terraform init
```

Run the following step to view the changes Terraform is going to make on your behalf.

```bash
terraform plan
```

Finally, run this step to make Terraform install the Kubernetes delegate using the Helm provider.

```bash
terraform apply
```

When prompted by Terraform if you want to continue with the apply step, enter `yes`, and then you will see output similar to the following.

```
helm_release.delegate: Creating...
helm_release.delegate: Still creating... [10s elapsed]
helm_release.delegate: Still creating... [20s elapsed]
helm_release.delegate: Still creating... [30s elapsed]
helm_release.delegate: Still creating... [40s elapsed]
helm_release.delegate: Still creating... [50s elapsed]
helm_release.delegate: Still creating... [1m0s elapsed]
helm_release.delegate: Creation complete after 1m0s [id=firstk8sdel]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
```

**Download a Kubernetes manifest template**

```bash
curl -LO https://raw.githubusercontent.com/harness/delegate-kubernetes-manifest/main/harness-delegate.yaml
```

**Replace variables in the template**

Open the `harness-delegate.yaml` file in a text editor and replace `PUT_YOUR_DELEGATE_NAME_HERE`, `PUT_YOUR_HARNESS_ACCOUNTID_HERE`, and `PUT_YOUR_DELEGATE_TOKEN_HERE` with your delegate name (for example, `firstk8sdel`), Harness `accountId`, and delegate token values, respectively.

Replace the `PUT_YOUR_MANAGER_HOST_AND_PORT_HERE` variable with the Harness Manager Endpoint noted below. For Harness SaaS accounts, you can find your Harness Cluster Location on the Account Overview page under the Account Settings section of the left navigation.

**Apply the Kubernetes manifest**

```bash
kubectl apply -f harness-delegate.yaml
```

**Prerequisites**

Ensure that you have the Docker runtime installed on your host. If not, use one of the following options to install Docker:

* Docker for Mac
* Docker for CentOS
* Docker for Ubuntu
* Docker for Debian
* Docker for Windows

**Install on Docker**

You can install delegates from the account, project, or org scope. In this example, install a delegate in the project scope.

Perform the following steps to install a delegate:

1. In Harness, select your project, then select **Project Settings**.
2. Under **Project-level resources**, select **Delegates**.
3. Select **Install a Delegate** to open the New Delegate dialog.
4. Under **Select where you want to install your Delegate**, select **Docker**.
5. Under **Install your Delegate**, enter a delegate name.
6. Copy the `docker run` command.

```bash
docker run --cpus=1 --memory=2g \
  -e DELEGATE_NAME=docker-delegate \
  -e NEXT_GEN="true" \
  -e DELEGATE_TYPE="DOCKER" \
  -e ACCOUNT_ID=YOUR_HARNESS_ACCOUNTID_ \
  -e DELEGATE_TOKEN=YOUR_DELEGATE_TOKEN \
  -e DELEGATE_TAGS="" \
  -e MANAGER_HOST_AND_PORT=YOUR_MANAGER_HOST_AND_PORT \
  harness/delegate:yy.mm.verno
```

The `docker run` command does not allow you to select the delegate token. You can replace the token in the command with another token if required.

Steps 6 and 7 are optional when installing a delegate using the CLI flow.

7. (Optional) Replace the `YOUR_MANAGER_HOST_AND_PORT_HERE` variable with the Harness Manager Endpoint noted below. For Harness SaaS accounts, to find your Harness cluster location, select **Account Settings**, then select **Overview**. In **Account Overview**, look in **Account Settings**. It is listed next to **Harness Cluster Hosting Account**.

Go to View account info and subscribe to downtime alerts to locate the Manager endpoint. For Harness CDCE, the endpoint varies based on the Docker vs. Helm installation options.

8. Run the command.

### Ephemeral storage in delegate Helm charts

To manage temporary disk space efficiently, you can configure ephemeral storage for the Harness Delegate using Helm charts. This section walks you through defining custom volumes and applying the configuration during Helm installation.

The setup is cloud-agnostic and works across providers by adjusting the storage class as needed.

1. Create a `values.yaml` file and add the following configuration to it.

   ```yaml
      custom_mounts:
      - mountPath: "/scratch"
         name: scratch-volume

      custom_volumes:
      - name: scratch-volume
         ephemeral:
            volumeClaimTemplate:
            metadata:
               labels:
                  type: <YOUR-TYPE-REFERENCE>
            spec:
               accessModes: [ "ReadWriteOnce" ]
               storageClassName: "<YOUR-STORAGE-CLASS>"
               resources:
                  requests:
                  storage: <STORAGE-SIZE>
   ```

   <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p><strong>Verify a StorageClass exists before installation</strong></p><p>Before proceeding with installation, ensure a suitable StorageClass exists in your cluster. This is required for provisioning ephemeral volumes as defined in your <code>values.yaml</code>.</p><p>You can check the available storage classes using:</p><pre class="language-bash"><code class="lang-bash">kubectl get storageclass
   </code></pre><p>If your cluster does not have a suitable <code>StorageClass</code>, create one using:</p><pre class="language-bash"><code class="lang-bash">kubectl apply -f storage-class.yaml
   </code></pre><p>Example <code>storage-class.yaml</code>:</p><pre class="language-yaml"><code class="lang-yaml">apiVersion: storage.k8s.io/v1
       kind: StorageClass
       metadata:
       name: &#x26;#x3C;YOUR-STORAGE-CLASS-NAME>
       provisioner: &#x26;#x3C;YOUR-STORAGE-PROVISIONER>  # e.g., kubernetes.io/aws-ebs, pd.csi.storage.gke.io
       parameters:
       type: &#x26;#x3C;YOUR-VOLUME-TYPE>               # e.g., gp2 for AWS
       reclaimPolicy: &#x26;#x3C;YOUR-RECLAIM-POLICY>     # e.g., Retain or Delete
       volumeBindingMode: WaitForFirstConsumer
   </code></pre><p>After creating the <code>StorageClass</code>, configure it in the Helm chart by setting: <code>--set persistence.storageClass=&#x26;#x3C;YOUR-STORAGE-CLASS-NAME></code></p></div>
2. Install the Helm chart using the example below, which applies the configuration from the `values.yaml` file created earlier:

   ```yaml
      helm upgrade -i <YOUR-DELEGATE-NAME> --namespace harness-delegate-ng --create-namespace \
      harness-delegate/harness-delegate-ng \
      --set delegateName=<YOUR-DELEGATE-NAME> \
      --set accountId=XXXXXXXXXXXXXXXX \
      --set delegateToken=XXXXXXXXXXXXXXXXXXXXXX \
      --set managerEndpoint=https://<YOUR-URL>.harness.io \
      --set delegateDockerImage=us-west1-docker.pkg.dev/gar-setup/docker/delegate:<DELEGATE-TAG-VERSION> \
      --set replicas=1 --set upgrader.enabled=true \
      -f values.yaml
   ```
3. Verify that the ephemeral storage is mounted correctly by inspecting the pod's volume mounts.

   * Get the pod name.

     ```bash
     kubectl get pods -n harness-delegate-ng
     ```

     Output:

     ```bash
     NAME                                  READY   STATUS    RESTARTS   AGE
     delegate-ephemeral-storage            1/1     Running   0          2m
     ```
   * Describe the pod.

     ```bash
     kubectl describe pod delegate-ephemeral-storage -n harness-delegate-ng
     ```

     Look for a section similar to the following in the output:

     ```bash
     Volumes:
     scratch-volume:
        Type:       PersistentVolumeClaim (a reference to a PVC)
        ClaimName:  scratch-volume-delegate-ephemeral-storage
        ReadOnly:   false

     Mounts:
     /scratch from scratch-volume (rw)
     ```

     This confirms that your ephemeral volume (`scratch-volume`) is mounted to `/scratch` in the pod.

   <div data-gb-custom-block data-tag="hint" data-style="warning" class="hint hint-warning"><p><strong>Ephemeral storage does not persist across pod restarts</strong></p><p>Ephemeral storage is automatically deleted when the pod is terminated, and a new volume is created when a new pod starts. This ties the storage to the pod's lifecycle, so it is not persistent.</p></div>

### Deploy using a custom role

During delegate installation, you have the option to deploy using a custom role. To use a custom role, you must edit the delegate YAML file.

Harness supports the following custom roles:

* `cluster-admin`
* `cluster-viewer`
* `namespace-admin`
* custom cluster roles

Perform the following steps to deploy using a custom cluster role:

1. Open the delegate YAML file in your text editor.
2. Add the custom cluster role to the `roleRef` field in the delegate YAML.

   ```yaml
   ---
   apiVersion: rbac.authorization.k8s.io/v1beta1
   kind: ClusterRoleBinding
   metadata:
     name: harness-delegate-cluster-admin
   subjects:
     - kind: ServiceAccount
       name: default
       namespace: harness-delegate-ng
   roleRef:
     kind: ClusterRole
     name: cluster-admin
     apiGroup: rbac.authorization.k8s.io
   ---
   ```

   In this example, the `cluster-admin` role is defined.
3. Save the delegate YAML file.

### Verify delegate connectivity

Select **Continue**. After the health checks pass, your delegate is available for you to use. Select **Done** and verify your new delegate is listed.

You can now route communication to external systems in Harness connectors and pipelines by selecting this delegate using a delegate selector.

### Troubleshooting

The delegate installer provides troubleshooting information for each installation process. If the delegate cannot be verified, select **Troubleshoot** for steps to resolve the problem. This section includes the same information.

Harness asks for feedback after the troubleshooting steps with the question **Did the delegate come up?**

If the steps did not resolve the problem, select **No**, and use the form to describe the issue. You will also find links to Harness Support and to [Delegate docs](https://developer.harness.io/docs/platform/delegates/delegate/delegate-concepts/delegate-overview).

**Troubleshoot a Helm installation**

Perform the following steps to troubleshoot your installation of the delegate using Helm:

1. Verify that Helm is correctly installed. Check for Helm:

   ```bash
   helm
   ```

   And then check for the installed version of Helm:

   ```bash
   helm version
   ```

   If you receive the message `Error: rendered manifests contain a resource that already exists...`, delete the existing namespace, and retry the Helm upgrade command to deploy the delegate. For further instructions on troubleshooting your Helm installation, go to the Helm troubleshooting guide.
2. Check the status of the delegate on your cluster:

   ```bash
   kubectl describe pods -n <NAMESPACE>
   ```
3. If the pod did not start, check the delegate logs:

   ```bash
   kubectl logs -f <DELEGATE_NAME> -n <NAMESPACE>
   ```
4. If the state of the delegate pod is `CrashLoopBackOff`, check your allocation of compute resources (CPU and memory) to the cluster. A state of `CrashLoopBackOff` indicates insufficient Kubernetes cluster resources.
5. If the delegate pod is not healthy, use the `kubectl describe` command to get more information:

   ```bash
   kubectl describe <POD_NAME> -n <NAMESPACE>
   ```

**Troubleshoot a Terraform installation**

Perform the following steps to troubleshoot your installation of the delegate using Terraform:

1. Verify that Terraform is correctly installed:

   ```bash
   terraform -version
   ```

   For further instructions on troubleshooting your installation of Terraform, go to the Terraform troubleshooting guide.
2. Check the status of the delegate on your cluster:

   ```bash
   kubectl describe pods -n <namespace>
   ```
3. If the pod did not start, check the delegate logs:

   ```bash
   kubectl logs -f <DELEGATE_NAME> -n <NAMESPACE>
   ```
4. If the state of the delegate pod is `CrashLoopBackOff`, check your allocation of compute resources (CPU and memory) to the cluster. A state of `CrashLoopBackOff` indicates insufficient Kubernetes cluster resources.
5. If the delegate pod is not healthy, use the `kubectl describe` command to get more information:

   ```bash
   kubectl describe <POD_NAME> -n <NAMESPACE>
   ```

**Troubleshoot a Kubernetes manifest installation**

Perform the following steps to troubleshoot your installation of the delegate using Kubernetes:

1. Check the status of the delegate on your cluster:

   ```bash
   kubectl describe pods -n <NAMESPACE>
   ```
2. If the pod did not start, check the delegate logs:

   ```bash
   kubectl logs -f <DELEGATE_NAME> -n <NAMESPACE>
   ```
3. If the state of the delegate pod is `CrashLoopBackOff`, check your allocation of compute resources (CPU and memory) to the cluster. A state of `CrashLoopBackOff` indicates insufficient Kubernetes cluster resources.
4. If the delegate pod is not healthy, use the `kubectl describe` command to get more information:

   ```bash
   kubectl describe <POD_NAME> -n <NAMESPACE>
   ```

**Troubleshoot a Docker installation**

Perform the following steps to troubleshoot your installation of the delegate using Docker:

1. Check the status of the delegate on your cluster:

   ```bash
   docker container ls -a
   ```
2. If the pod is not running, check the delegate logs:

   ```bash
   docker container logs <DELEGATE_NAME> -f
   ```
3. Restart the delegate container. To stop the container:

   ```bash
   docker container stop <DELEGATE_NAME>
   ```

   To start the container:

   ```bash
   docker container start <DELEGATE_NAME>
   ```
4. Ensure the container has sufficient CPU and memory resources. If not, remove the older containers:

   ```bash
   docker container rm [container id]
   ```

</details>

### Configure your AWS credentials and Docker endpoint in Harness

Especially with a private registry or repository, credentials for the repository are usually scattered around a few scripts or prompted by a system to enter before deployment. Harness has a concept of a Cloud Connector, which manages the persistence of your cloud provider credentials and uses them on your behalf.

To create an AWS Cloud Provider connector, go to **Account Settings** -> **Account Resources** -> **Connectors**, then select **+ New Connector** -> **AWS**.

Name the connector `my_aws_connector`.

![Creating a new AWS connector in Harness](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-6437c7cfd881d410029c1eb867a1eeb3bb1445e5%2Fmy-aws-connector.png?alt=media)

Click **Continue** and pick your authentication mechanism. If you have an AWS access key and secret, you can enter those as encrypted credentials, which are stored in the Harness Secrets Manager.

For example, you can create `my_aws_access` for your access key and `my_aws_secret` for the secret.

![Entering AWS access key and secret credentials in Harness](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-bea8f63c01673fe9349ce6daae88aad018c18a23%2Faws-creds.png?alt=media)

Click **Continue** and select how you want to connect. You can use the Harness Platform or a delegate to connect. In this example, connecting through Harness is fine.

![Selecting the connection method for the AWS connector](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-78d41466c350d842bfa86d0b7195d5337f368405%2Faws-connect-harness.png?alt=media)

Click **Save and Continue** and your credentials are tested. Once successful, you can modify one last item so you can pull images from public Docker Hub in the example.

### Configure the Harness Docker connector

By default, Harness is wired to the public Docker Hub. Depending on the image, the API endpoint can be different. The endpoint to use in this example is `https://registry.hub.docker.com/v2/`.

Go to **Account Settings** -> **Account Connectors** -> **Harness Docker Connector**, then select **Edit**.

![Editing the Harness Docker connector](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-cbbf41d9b8448a1802e9bb4370819371b721ba38%2Fedit-dh-conn.png?alt=media)

Modify the endpoint, if it is not already set, to `https://registry.hub.docker.com/v2/`.

![Entering the Docker Hub endpoint details](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-5d4a50f36630bfac573b400abd9a99cb399ce872%2Fdh-details.png?alt=media\&token=8d1f9c89-9080-4d07-9f8d-c51144b87267)

Click **Continue** to save. Running this connector through the Harness Platform is fine. Once saved and validated, Harness is wired to that API endpoint.

![The updated Docker Hub connector details](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-c11d3d460e53a21be56c994e4838ba5fa1c11a68%2Fupdated-dh.png?alt=media)

With those connectors configured, you are ready to create an ECS pipeline. To speed up pipeline creation, wire in a pair of configuration files.

### Create Harness-hosted configuration files

Harness executes your configuration files for you. For this example, wire in two configuration files: an ECS task definition JSON file and an ECS service definition JSON file. These manifests can be linked to source control or stored in Harness itself. For ease of use, you can wire and modify these files to fit your ECS role and security group or subnet items inside Harness.

ECS task JSON: <https://github.com/harness-apps/developer-hub-apps/blob/main/applications/first-ecs-example/ecs_task.json>

Service definition JSON: <https://github.com/harness-apps/developer-hub-apps/blob/main/applications/first-ecs-example/service_definition.json>

To create a manifest hosted by Harness, add these at the account level.

Go to **Account Settings** -> **Account Resources** -> **File Store**, then select **+ New**.

Create two new files, one called `ecs_task.json` and one called `service_definition.json`, based on the files above in [GitHub](https://github.com/harness-apps/developer-hub-apps/tree/main/applications/first-ecs-example). Copy and paste the contents into each respective file and save each.

![Creating files in the Harness File Store](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-d2b188a02ddd74324da96ccce96a0df7205a6000%2Fharness-file-store.png?alt=media)

For the [ECS task JSON](https://github.com/harness-apps/developer-hub-apps/blob/main/applications/first-ecs-example/ecs_task.json), on lines 3 and 53, replace the value of `executionRoleArn` with your `ecsInstanceRole`.

For the [service definition JSON](https://github.com/harness-apps/developer-hub-apps/blob/main/applications/first-ecs-example/service_definition.json), on line 8, replace the security group with your applicable security group. On lines 11, 12, and 13, replace the subnets with your subnet IDs for the availability zones selected when the ECS cluster was created. You can add or remove items in the subnet array depending on the number of subnets you have.

With those manifests configured, creating the ECS pipeline is quick.

***

## Create an ECS Harness pipeline

With the delegate, ECS cluster, and manifests created, creating a Harness pipeline is straightforward. Using the default Harness project is fine for the example.

Create a pipeline with the following details:

* **Navigation**: **Deployments** -> **Pipelines**, then select **+ Create new Pipeline**
* **Name**: `my-first-ecs-pipeline`
* **Setup**: In-line

![Creating a new pipeline in Harness](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-6a01fda43be21d60ecd5538b6ae281d40279964f%2Fnew-pipeline.png?alt=media)

Once you click **Start**, you can add an ECS deployment stage. Select **+ Add Stage** -> **Deployment**, then select **Amazon ECS**.

Stage name: `deploy-to-ecs`

![Adding an Amazon ECS deployment stage](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-20b66c19780e375a123f727397f9a9e27b262d34%2Fdeploy-to-ecs.png?alt=media)

Click **Setup Stage**. The next step creates a Harness service that represents the ECS configurations and artifact that need to be deployed.

In the service configuration, click **+ New Service**.

![Creating a new Harness service](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-3cebff44f2cb6d4cbd2f305adb53c4ee5121f771%2Fnew-service.png?alt=media)

In the New Service UI, name the new service `sample-container` and prepare to add the task and service definitions.

![Naming the new service sample-container](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-7c5ef0e053ff2bd99700bd7c662fd5d170e60dfe%2Fsample-container.png?alt=media)

To add the task definition, click **+ Add Task Definition**. Select **Harness** as the task definition store.

![Adding a task definition from the Harness file store](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-295f25af3e6b047404b59e3d6b8cf92d9fbd447b%2Ftask-def.png?alt=media)

Select and name the `ecs_task.json` file that was created earlier.

Manifest name: `Task Def`

![Selecting the ecs\_task.json manifest path](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-4ca3e274a3a6ee4a50c2bde9194c1d1a9edf1a2a%2Ftask-path.png?alt=media)

Repeat the same process for the service definition once saved. Click **+ Add Service Definition**.

Name: `Service Def`

![Adding the service definition manifest](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-8e5f2ad0a7313fd311361d40a6155a6a352520f3%2Fservice-def.png?alt=media)

Now both are wired. The next step is to wire in the artifact or image that you want to deploy.

![Both the task and service definitions wired to the service](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-7df814cab72571a29e747f815832fac648620926%2Fmanifests-wired.png?alt=media)

Lastly, wire in an artifact to deploy. In the task definition, a variable has been added, if you copied from source control, to take in an input from Harness for the image to deploy.

![An input variable for the image to deploy in the task definition](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-4d4fd557cf32a95a386a4f572677f111426f6ff6%2Finput-variable.png?alt=media)

Specify that image in Harness by adding an artifact source. Click **+ Add Artifact Source**.

Select **Docker Registry**, then select the public Docker Hub connector you configured earlier.

![Selecting the Docker Registry artifact source](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-3d5a40f71517969bfe28e84f623f73e35b694bee%2Fdocker-source.png?alt=media)

Click **Continue**. Nginx can be used as an example to start.

* **Artifact source name**: `nginx`
* **Image path**: `library/nginx`

![Entering the artifact source name and image path](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-3a4399149dacb5f6b50d50235524981de3436b83%2Fartifact-details.png?alt=media)

Click **Submit** and the artifact is wired in. Then click **Save**.

![The artifact wired to the service](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-e9dbb04d7fe18280705c627f8dd7f503e0159db5%2Fartifact-wired.png?alt=media)

Click **Continue** to point Harness to your ECS cluster.

![The completed sample-container service](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-7051e4f6e4bc52be0d1b85ab3d706f9cbb70329e%2Fsample-container-complete.png?alt=media)

### Point Harness to ECS

Harness has a concept of environments, which represent the target infrastructure where you want to deploy. In this case, you will be deploying to the ECS cluster that was created earlier.

![Specifying the deployment environment](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-d8a55b96b3f48e0fb25edae490f05d2ee7341be6%2Fspecifiy-env.png?alt=media)

Click **+ New Environment**.

* **Name**: `my-aws-environment`
* **Environment type**: Pre-Production

![Creating a new environment](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-46bef1336fe6e925320c90a0eedc7e5bfea042a5%2Fnew-env.png?alt=media)

Click **Save**, and next you point to your specific ECS cluster by adding it as a piece of infrastructure. Click **+ New Infrastructure**.

![Adding new infrastructure](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-42f94d4a48a222996e8daa98817e833c7c0c081a%2Fnew-infra.png?alt=media)

* **Name**: `my-ecs-instance`
* **Connector**: your AWS connector
* **Region**: your AWS Region where the ECS cluster lives
* **Cluster**: `harness-ecs`

![Selecting the ECS cluster for the infrastructure definition](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-7db28b3954ded69dd3f39d18a9601360f395114d%2Fpick-ecs.png?alt=media)

Click **Save**, then **Continue** to define the execution strategy.

![The configured ECS infrastructure](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-b3c69853013494811d73fdbe6912384181dacc7a%2Fmy-ecs.png?alt=media)

In the execution strategy, there are several options for how to deploy to ECS. For this example, use a rolling deployment strategy.

![Selecting the rolling deployment execution strategy](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-4eec15f918de1b089d64b26c10db6fa411097f9a%2Fexec-strat.png?alt=media)

Once selected, click **Use Strategy**. Your pipeline is now ready to be saved. Click **Save** in the top right.

![Saving the completed pipeline](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-27e2962e81f5c572c2829f5853f2126c91357c39%2Fsave-pipeline.png?alt=media)

Now you are ready to execute the pipeline.

### Run your first Harness ECS deployment

From **Deployments** -> **Pipelines**, select your pipeline, then click **Run** to execute it.

Enter the following run inputs:

* **Primary Artifact**: `nginx`
* **Tag**: `stable`

![Entering run inputs for the pipeline](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-c50f03c8e798b33c36055ed04450a9bd6a9b9f3f%2Frun.png?alt=media)

Click **Run Pipeline** and your pipeline executes.

After a few moments, your pipeline is successfully deployed to ECS.

![A successful pipeline execution](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-2dcbcf6c4ed805035c18fe4952f6c419441b06e1%2Fsuccess.png?alt=media)

To view your workload in action, go back to the AWS Console and open the task to find the public IP.

Go to **AWS Console** -> **ECS** -> **Clusters** -> **harness-ecs** -> **Tasks** -> **Task UID** -> **Public IP**.

![Finding the public IP for the running ECS task](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-093737756ee65c85490f3e672edb74dc70b58ed9%2Fecs-network.png?alt=media)

Go to the public IP, for example `52.15.55.133`, and you see a welcome message.

![The welcome message returned by the deployed container](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-215f22375c56b1d5dc14cea7a280f7d8ead50edd%2Fwelcome.png?alt=media)

This was a basic deployment to ECS, and Harness can orchestrate confidence-building steps on top of it. This tutorial used a pre-packaged image, but [Harness CI](https://developer.harness.io/docs/continuous-integration/overview) can run a Docker build for you and create a custom image, which you can then deploy with a similar process into Amazon ECS.

***

## Next steps

* [AWS deployment FAQs](https://developer.harness.io/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/aws/aws-deployment-faqs.md): Find answers to common questions about deploying to AWS with Harness.
* [CD best practices](https://developer.harness.io/continuous-delivery/troubleshooting-and-resources/cd-best-practices.md): Review recommended practices for running Continuous Delivery pipelines in production.
* [Monitor CD deployments](https://developer.harness.io/continuous-delivery/use-continuous-delivery/monitor-deployments/monitor-cd-deployments.md): Learn how to monitor the health of your deployments after they run.
