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

# ECS canary deployment

Deploy an ECS service using the canary strategy, which validates a small canary instance before deleting it and running a full rolling deployment.

The canary strategy deploys a lightweight canary version of the service alongside production, lets you validate it, then deletes the canary and runs a full rolling deployment to replace all existing instances. Use this strategy when you want to test the new version with real traffic before committing to a full rollout.

***

## What you will learn from this topic

* How Harness creates, validates, and removes the canary instance.
* How to configure the canary instance count and service naming suffix.

***

## 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.

***

## Stage YAML

```yaml
pipeline:
  stages:
    - name: Deploy ECS
      id: deployEcs
      service:
        type: ecs
        items:
          - <service-id>
      environment:
        items:
          - id: <environment-id>
            deploy-to: all
      runtime: cloud
      on-failure:
        errors: all
        action: stage-rollback
      steps:
        - name: ECS Canary Deploy
          id: ecsCanaryDeployStep
          template:
            uses: ecsCanaryDeployStep
        - name: ECS Canary Delete
          id: ecsCanaryDeleteStep
          template:
            uses: ecsCanaryDeleteStep
            with:
              service: ${{stage.steps.ecsCanaryDeployStep.output.outputVariables.canaryService}}
        - name: ECS Rolling Deploy
          id: ecsRollingDeployStep
          template:
            uses: ecsRollingDeployStep
      rollback:
        - group:
            id: ecsRollbackGroup
            name: ECS Rollback Group
            steps:
              - name: ECS Canary Delete Rollback
                id: ecsCanaryDeleteRollback
                template:
                  uses: ecsCanaryDeleteStep
                  with:
                    service: ${{stage.steps.ecsCanaryDeployStep.output.outputVariables.canaryService}}
              - name: ECS Rolling Rollback
                id: ecsRollingRollbackStep
                template:
                  uses: ecsRollingRollbackStep
                  with:
                    curr_service: ${{stage.steps.ecsRollingDeployStep.output.outputVariables.currService}}
                    first_deployment: ${{stage.steps.ecsRollingDeployStep.output.outputVariables.firstDeployment}}
                    skip_app_scaling: ${{stage.steps.ecsRollingDeployStep.output.outputVariables.scalingSkipped}}
```

***

## How this deployment works

When you select the canary strategy, Harness adds the following steps to your stage execution:

1. **ECS Canary Deploy**: Registers a new task definition revision and creates a canary service at the specified instance count. The canary service name is the base service name with the configured suffix appended (for example, `my-service` → `my-serviceCanary`). After the canary reaches steady state, Harness registers scalable targets and scaling policies on the canary service.
2. **ECS Canary Delete**: Deletes the canary service after validation. By default, Harness resolves the canary service name from the ECS Canary Deploy step's output. Add approval steps, tests, or conditional steps between ECS Canary Deploy and ECS Canary Delete to gate promotion.
3. **ECS Rolling Deploy**: Runs a full rolling deployment to update the production service with the new task definition. Harness creates or updates the service, waits for steady state, and applies scaling configuration.

The rollback group runs automatically if the stage failure strategy triggers:

1. **ECS Canary Delete Rollback**: Deletes the canary service, using the same `canaryService` output expression as the forward-path ECS Canary Delete step.
2. **ECS Rolling Rollback**: Restores the production service to the task definition captured before the ECS Rolling Deploy step ran, wired from ECS Rolling Deploy's output variables.

{% hint style="info" %}
**Add gates between canary and delete**

You can insert approval steps, HTTP steps, or any other steps between ECS Canary Deploy and ECS Canary Delete to validate the canary before proceeding. The canary service stays up until ECS Canary Delete runs.
{% endhint %}

***

## Configure the ECS Canary Deploy step

None of the ECS Canary Deploy step's fields are required. The following are the ones you are most likely to adjust.

| Field                          | Required | Description                                                                                              |
| ------------------------------ | -------- | -------------------------------------------------------------------------------------------------------- |
| **Desired Count Override**     | No       | The number of canary instances to run. Leave empty to use the desired count from the service definition. |
| **Canary Service Name Suffix** | No       | The string appended to the base service name to form the canary service name. Default is `Canary`.       |

Go to [ECS Canary Deploy step](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/step-library/ecs-canary-deploy.md) for the full field reference.

***

## Configure the ECS Canary Delete step

The ECS Canary Delete step is required in this strategy. It removes the canary service after validation.

| Field                            | Required | Description                                                                                                                                                                                   |
| -------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **ECS Canary Service to Delete** | Yes      | The name of the canary service to delete. Defaults to the `canaryService` output from the ECS Canary Deploy step. Do not change this field unless you are using a custom canary service name. |

Go to [ECS Canary Delete step](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/step-library/ecs-canary-delete.md) for the full field reference.

***

## Configure the ECS Rolling Deploy step

The ECS Rolling Deploy step uses the same task definition registered by ECS Canary Deploy. It performs a full in-place update of the production service. None of its fields are required; the following are the ones you are most likely to adjust.

| Field                       | Required | Description                                                                |
| --------------------------- | -------- | -------------------------------------------------------------------------- |
| **Force New Deployment**    | No       | Forces a redeployment even when the task definition has not changed.       |
| **Match Running Instances** | No       | Sets the new desired count to match the current running instance count.    |
| **Skip App Scaling**        | No       | Skips registering scalable targets and scaling policies during deployment. |

Go to [ECS Rolling Deploy step](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/step-library/ecs-rolling-deploy.md) for the full field reference.

***

## Rollback behavior

The rollback group runs both steps in sequence when the stage failure strategy triggers.

* **ECS Canary Delete Rollback:** Deletes the canary service if it is still running, using the same `canaryService` output expression as the forward-path ECS Canary Delete step. If the canary service was already deleted (for example, if the failure happened in ECS Rolling Deploy), this step is a no-op.
* **ECS Rolling Rollback:** Restores the production service to the task definition and desired count captured before ECS Rolling Deploy ran, wired from its `currService`, `firstDeployment`, and `scalingSkipped` output variables. On first deployment (no prior service), Harness deletes the service that was created by ECS Rolling Deploy and waits for it to drain.

***

## Next steps

* Go to [ECS basic deployment](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/ecs-deployment-strategies/basic.md) for a simpler upgrade-in-place strategy without a canary phase.
* Go to [ECS rolling deployment](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/ecs-deployment-strategies/rolling.md) to run a rolling deploy without a canary phase.
* Go to [ECS BlueGreen Deploy With Swap Strategy](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/ecs-deployment-strategies/blue-green-swap.md) or [ECS BlueGreen Deploy With Traffic Shift Strategy](https://developer.harness.io/continuous-delivery/new-experience/use-deployments/ecs-deployments/ecs-deployment-strategies/blue-green-traffic-shift.md) for a zero-downtime swap between two target groups.
