> 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/use-continuous-delivery/deploy-services-on-different-platforms/aws/ecs/ecs-canary-phased-traffic-shift.md).

# ECS basic deployments with phased traffic shifting and scaling

Phased traffic shifting and scaling in ECS using basic deployment strategy and custom listener rules.

You can deploy ECS services using a basic strategy with phased traffic shifting and scaling, incrementally increasing the new service instances while decreasing the old service instances.

This topic explains the differences between a standard basic strategy and one with phased traffic shifting and scaling, and explains how to set up a basic strategy with phased traffic shifting and scaling.

***

## What you will learn from this topic

* How to compare a [standard basic strategy](#standard-basic-strategy) with [basic phased traffic shifting and scaling](#basic-with-phased-traffic-shifting-and-scaling).
* How to [set up basic with phased traffic shifting](#set-up-basic-with-phased-traffic-shifting).
* How to configure the [ECS Service Setup step](#ecs-service-setup-step) and [ECS Upgrade Container steps](#first-ecs-upgrade-container-step).
* How to [add ECS Upgrade Container steps for traffic shifting and scaling](#add-ecs-upgrade-container-steps-for-traffic-shifting-and-scaling).

***

## Before you begin

The following prerequisites apply to ECS basic deployments with phased traffic shifting and scaling:

* **ECS service and infrastructure**: A Harness CD service configured for ECS and an environment with an ECS infrastructure definition. Go to [Amazon ECS deployment tutorial](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/aws/ecs/ecs-deployment-tutorial.md) to set up the service and infrastructure.
* **Pipeline permissions**: View, Create/Edit, and Execute on Pipelines. Go to [RBAC in Harness](https://developer.harness.io/docs/platform/role-based-access-control/rbac-in-harness) to configure roles.
* **Optional Continuous Verification**: If you insert an AI Verify (v1) step between Upgrade Container steps, configure Continuous Verification. Go to [Verify deployments with the Verify step](/continuous-delivery/use-continuous-delivery/verify-deployments/verify-deployments-with-the-verify-step.md) for details.

***

## Standard basic vs phased

You have two strategy options when performing an ECS basic deployment in Harness: standard basic and basic with phased traffic shifting and scaling.

### Standard basic strategy

In a standard ECS basic deployment, Harness deploys the ECS service using your ECS service definition in an ECS Service Setup step, and then upgrades the container using an ECS Upgrade Container step to a percentage of the ECS service definition `desiredCount` or to a specific number of instances.

![ECS Service Setup and single ECS Upgrade Container steps in a basic deployment](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-d537ac7c2fd2807e1a12c7955f844b861b9f3c90%2F8c9c2a38d604ba1c878cfe7f4f0073769dbbae4b927443979f8fe71eabcf6522.png?alt=media)

### Basic with phased traffic shifting and scaling

Basic with phased traffic shifting and scaling is the same as standard basic but includes multiple ECS Upgrade Container steps, each deploying a percentage of the `desiredCount` until it reaches 100% or a specific number of instances.

The following video provides an overview:

{% embed url="<https://www.loom.com/share/9ba108c0fc84403795895261c5671a02?sid=004122a0-66a2-4f67-9f7e-f7039da7c22e>" %}

The following pipeline demonstrates an ECS deployment with phased traffic shifting. There are two `EcsUpgradeContainer` steps.

The first `EcsUpgradeContainer` step upgrades the container to 50% of the `desiredCount` in the ECS service definition, and the next `EcsUpgradeContainer` step upgrades the container to 100%.

<details>

<summary>ECS basic strategy with phased traffic shifting sample pipeline YAML</summary>

```yaml
pipeline:
  name: EcsPipeline
  identifier: EcsPipeline
  projectIdentifier: default
  orgIdentifier: default
  tags: {}
  stages:
    - stage:
        name: ecs
        identifier: ecs
        description: ""
        type: Deployment
        spec:
          deploymentType: ECS
          service:
            serviceRef: EcsService1_B5
          execution:
            steps:
              - step:
                  type: EcsServiceSetup
                  name: ECS Service Setup
                  identifier: EcsServiceSetup_1
                  spec:
                    resizeStrategy: ResizeNewFirst
                  timeout: 10m
              - step:
                  type: EcsUpgradeContainer
                  name: 50 Percent Traffic Increase
                  identifier: EcsUpgradeContainer_1
                  spec:
                    newServiceInstanceCount: 50
                    newServiceInstanceUnit: Percentage
                  timeout: 10m
              - step:
                  type: EcsUpgradeContainer
                  name: 100 Percentage Traffic Increase
                  identifier: EcsUpgradeContainer_2
                  spec:
                    newServiceInstanceCount: 100
                    newServiceInstanceUnit: Percentage
                  timeout: 10m
            rollbackSteps:
              - step:
                  type: EcsBasicRollback
                  name: EcsBasicRollback_1
                  identifier: EcsBasicRollback_1
                  spec: {}
                  timeout: 10m
          environment:
            environmentRef: EcsEnv_yV
            deployToAll: false
            infrastructureDefinitions:
              - identifier: EcsInfra_Jf
        tags: {}
        failureStrategies:
          - onFailure:
              errors:
                - AllErrors
              action:
                type: StageRollback
        variables:
          - name: runTaskName
            type: String
            description: ""
            value: runTask-auto
          - name: runTaskCount
            type: Number
            description: ""
            value: 1
          - name: var1
            type: String
            description: ""
            value: ecs-auto-iG
```

</details>

The ECS basic strategy with phased traffic shifting and scaling performs the following steps:

1. **ECS Service Setup step**: Create a new ECS service with 0 instances.
2. **First ECS Upgrade Container step**: Upgrade instances of new service by X% (or count) and decrease instances of old service by Y% (or count).
   1. (Optional) Perform Harness [Continuous Verification (CV)](/continuous-delivery/use-continuous-delivery/verify-deployments/verify-deployments-with-the-verify-step.md). Once CV is performed, step 2 is run again.
3. **Additional ECS Upgrade Container step(s)**: Upgrade the new service to 100% (or count) and the old service to 0% (or count).

![Multiple ECS Upgrade Container steps for phased traffic shifting](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-18e1a944f902ed4ae9a3d5e284464842a061882d%2F86df8a74474e01a5a6469a9fbc0b8ff60b1dc4366c22be3184a3afacadf5eee6.png?alt=media)

***

## Set up basic with phased traffic shifting

Perform the following steps to set up an ECS basic deployment with phased traffic shifting and scaling:

1. Add an ECS stage to your pipeline.
2. Add a Harness service in the stage **Service**.
3. Add a Harness environment and infrastructure in the stage **Environment**.
4. Select the basic deployment strategy in the stage **Execution**.
5. Configure the **ECS Service Setup** step, described below.
6. Configure the first **ECS Upgrade Container** step, described below.
7. Add and configure additional **ECS Upgrade Container** step(s), described below.

***

## ECS Service Setup step

The ECS Service Setup step uses the ECS service definition in the stage's **Service** setting to create a new ECS service with 0 instances.

The ECS Service Setup step has the following settings.

### Resize Strategy

You can define whether to upsize the new service first or downsize the old service first in later steps. By default, Harness upsizes the new service first.

### Same as already running instances

When **Same as already running instances** is selected, the new ECS service is deployed with the same instances as the old service after the deployment is completed.

***

## First ECS Upgrade Container step

The ECS Upgrade Container step upgrades the number of instances of the new service by X% (or count) and decreases instances of the old service by Y% (or count).

### Instance Count and Instance Unit

**Instance Count** specifies the desired count for the new service. The default is 100 percent.

For phased traffic shifting, enter an incremental percentage (or count), such as 50 percent. Subsequent ECS Upgrade Container steps can increase the percentage until it reaches 100 percent or the full count you desire.

**Percentage** refers to a percentage of the `desiredCount` in the ECS service definition you are using.

**Count** overrides the `desiredCount` in the ECS service definition you are using.

### Downsize Instance Count and Downsize Instance Count Unit

**Downsize Instance Count** specifies the instance count/percentage for the old service.

***

## Add ECS Upgrade Container steps for traffic shifting and scaling

To perform phased traffic shifting and scaling, you use multiple ECS Upgrade Container steps, each incrementing the instance count/percentage until it reaches 100% or a specific count.

If you use percentage, then you are increasing the number of instances by a percentage of the `desiredCount` in the ECS service definition you are deploying.

If you use count, you are overriding the `desiredCount` in the ECS service definition with a specific instance count.

***

## Advanced settings

All steps include the following **Advanced** settings:

* [Delegate Selector](https://developer.harness.io/docs/platform/delegates/manage-delegates/select-delegates-with-selectors)
* [Conditional Execution](https://developer.harness.io/docs/platform/pipelines/step-skip-condition-settings)
* [Failure Strategy](https://developer.harness.io/docs/platform/pipelines/failure-handling/define-a-failure-strategy-on-stages-and-steps)
* [Looping Strategy](https://developer.harness.io/docs/platform/pipelines/looping-strategies-matrix-repeat-and-parallelism/)
* [Policy Enforcement](https://developer.harness.io/docs/platform/governance/policy-as-code/harness-governance-overview)

***

## Troubleshooting

The following issues are common when you configure phased ECS traffic shifting:

<details>

<summary>New service does not reach the expected instance count</summary>

Confirm each ECS Upgrade Container step's **Instance Count** and **Instance Unit** add up to the final desired percentage or count. If you use **Percentage**, values are relative to `desiredCount` in the ECS service definition.

</details>

<details>

<summary>Old service instances are not reduced as expected</summary>

Set **Downsize Instance Count** and **Downsize Instance Count Unit** on each Upgrade Container step, and confirm **Resize Strategy** on ECS Service Setup matches whether you upsize the new service or downsize the old service first.

</details>

<details>

<summary>Deployment rolls back after Continuous Verification</summary>

If an AI Verify (v1) step fails between Upgrade Container steps, the stage failure strategy can trigger rollback. Review the AI Verify (v1) step configuration and the stage failure strategy before re-running.

</details>

***

## Next steps

* [Amazon ECS deployment tutorial](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/aws/ecs/ecs-deployment-tutorial.md): Set up an ECS service, infrastructure, and basic deployment.
* [ECS traffic shifting](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/aws/ecs/traffic-shifting.md): Configure listener-rule traffic shifting for ECS.
* [ECS scale](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/aws/ecs/ecs-scale.md): Scale ECS services independently of a phased upgrade sequence.
* [Verify deployments with the Verify step](/continuous-delivery/use-continuous-delivery/verify-deployments/verify-deployments-with-the-verify-step.md): Insert Continuous Verification between Upgrade Container steps.

{% @harness-feedback/feedback %}
