# EcsBlueGreenDeploymentConfig

Specify how the deployment behaves and how traffic is routed to the ECS service during a blue-green ECS deployment.

- Source: [`aws-codedeploy/lib/ecs/deployment-group.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-codedeploy/lib/ecs/deployment-group.ts#L59)
- Type last changed: v2.234.0 · 8 Jan 2026

## Example

TypeScript:

```ts
declare const myApplication: codedeploy.EcsApplication;
declare const cluster: ecs.Cluster;
declare const taskDefinition: ecs.FargateTaskDefinition;
declare const blueTargetGroup: elbv2.ITargetGroup;
declare const greenTargetGroup: elbv2.ITargetGroup;
declare const listener: elbv2.IApplicationListener;

const service = new ecs.FargateService(this, 'Service', {
  cluster,
  taskDefinition,
  deploymentController: {
    type: ecs.DeploymentControllerType.CODE_DEPLOY,
  },
});

new codedeploy.EcsDeploymentGroup(this, 'BlueGreenDG', {
  service,
  blueGreenDeploymentConfig: {
    blueTargetGroup,
    greenTargetGroup,
    listener,
  },
  deploymentConfig: codedeploy.EcsDeploymentConfig.CANARY_10PERCENT_5MINUTES,
});
```

Python:

```python
# my_application: codedeploy.EcsApplication
# cluster: ecs.Cluster
# task_definition: ecs.FargateTaskDefinition
# blue_target_group: elbv2.ITargetGroup
# green_target_group: elbv2.ITargetGroup
# listener: elbv2.IApplicationListener

service = ecs.FargateService(self, "Service",
    cluster=cluster,
    task_definition=task_definition,
    deployment_controller=ecs.DeploymentController(
        type=ecs.DeploymentControllerType.CODE_DEPLOY
    )
)

codedeploy.EcsDeploymentGroup(self, "BlueGreenDG",
    service=service,
    blue_green_deployment_config=codedeploy.EcsBlueGreenDeploymentConfig(
        blue_target_group=blue_target_group,
        green_target_group=green_target_group,
        listener=listener
    ),
    deployment_config=codedeploy.EcsDeploymentConfig.CANARY_10PERCENT_5MINUTES
)
```

Java:

```java
EcsApplication myApplication;
Cluster cluster;
FargateTaskDefinition taskDefinition;
ITargetGroup blueTargetGroup;
ITargetGroup greenTargetGroup;
IApplicationListener listener;

FargateService service = FargateService.Builder.create(this, "Service")
        .cluster(cluster)
        .taskDefinition(taskDefinition)
        .deploymentController(DeploymentController.builder()
                .type(DeploymentControllerType.CODE_DEPLOY)
                .build())
        .build();

EcsDeploymentGroup.Builder.create(this, "BlueGreenDG")
        .service(service)
        .blueGreenDeploymentConfig(EcsBlueGreenDeploymentConfig.builder()
                .blueTargetGroup(blueTargetGroup)
                .greenTargetGroup(greenTargetGroup)
                .listener(listener)
                .build())
        .deploymentConfig(EcsDeploymentConfig.CANARY_10PERCENT_5MINUTES)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
EcsApplication myApplication;
Cluster cluster;
FargateTaskDefinition taskDefinition;
ITargetGroup blueTargetGroup;
ITargetGroup greenTargetGroup;
IApplicationListener listener;

var service = new FargateService(this, "Service", new FargateServiceProps {
    Cluster = cluster,
    TaskDefinition = taskDefinition,
    DeploymentController = new DeploymentController {
        Type = DeploymentControllerType.CODE_DEPLOY
    }
});

new EcsDeploymentGroup(this, "BlueGreenDG", new EcsDeploymentGroupProps {
    Service = service,
    BlueGreenDeploymentConfig = new EcsBlueGreenDeploymentConfig {
        BlueTargetGroup = blueTargetGroup,
        GreenTargetGroup = greenTargetGroup,
        Listener = listener
    },
    DeploymentConfig = EcsDeploymentConfig.CANARY_10PERCENT_5MINUTES
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var myApplication EcsApplication
var cluster Cluster
var taskDefinition FargateTaskDefinition
var blueTargetGroup ITargetGroup
var greenTargetGroup ITargetGroup
var listener IApplicationListener

service := ecs.NewFargateService(this, jsii.String("Service"), &FargateServiceProps{
	Cluster: Cluster,
	TaskDefinition: TaskDefinition,
	DeploymentController: &DeploymentController{
		Type: ecs.DeploymentControllerType_CODE_DEPLOY,
	},
})

codedeploy.NewEcsDeploymentGroup(this, jsii.String("BlueGreenDG"), &EcsDeploymentGroupProps{
	Service: Service,
	BlueGreenDeploymentConfig: &EcsBlueGreenDeploymentConfig{
		BlueTargetGroup: *BlueTargetGroup,
		GreenTargetGroup: *GreenTargetGroup,
		Listener: *Listener,
	},
	DeploymentConfig: codedeploy.EcsDeploymentConfig_CANARY_10PERCENT_5MINUTES(),
})
```

## Properties

- `blueTargetGroup`: [ITargetGroup](/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.ITargetGroup.html) (required) — The target group that will be associated with the 'blue' ECS task set during a blue-green deployment.

- `deploymentApprovalWaitTime`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) = 0 — Specify how long CodeDeploy waits for approval to continue a blue-green deployment before it stops the deployment.

  After provisioning the 'green' ECS task set and re-routing test traffic, CodeDeploy can wait for approval before
  continuing the deployment and re-routing production traffic.  During this wait time, validation such as manual
  testing or running integration tests can occur using the test traffic port, prior to exposing the new 'green' task
  set to production traffic.  To approve the deployment, validation steps use the CodeDeploy
  [ContinueDeployment API(https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_ContinueDeployment.html).
  If the ContinueDeployment API is not called within the wait time period, CodeDeploy will stop the deployment.

  By default, CodeDeploy will not wait for deployment approval.  After re-routing test traffic to the 'green' ECS task set
  and running any 'AfterAllowTestTraffic' and 'BeforeAllowTraffic' lifecycle hooks, the deployment will immediately
  re-route production traffic to the 'green' ECS task set.

- `greenTargetGroup`: [ITargetGroup](/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.ITargetGroup.html) (required) — The target group that will be associated with the 'green' ECS task set during a blue-green deployment.

- `listener`: [IListenerRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_elasticloadbalancingv2.IListenerRef.html) (required) — The load balancer listener used to serve production traffic and to shift production traffic from the 'blue' ECS task set to the 'green' ECS task set during a blue-green deployment.

- `terminationWaitTime`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) = 0 — Specify how long CodeDeploy waits before it terminates the original 'blue' ECS task set when a blue-green deployment is complete.

  During this wait time, CodeDeploy will continue to monitor any CloudWatch alarms specified for the deployment group,
  and the deployment group can be configured to automatically roll back if those alarms fire.  Once CodeDeploy begins to
  terminate the 'blue' ECS task set, the deployment can no longer be rolled back, manually or automatically.

  By default, the deployment will immediately terminate the 'blue' ECS task set after production traffic is successfully
  routed to the 'green' ECS task set.

- `testListener`: [IListenerRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_elasticloadbalancingv2.IListenerRef.html) — The load balancer listener used to route test traffic to the 'green' ECS task set during a blue-green deployment.

  **Default:** No test listener will be added

  During a blue-green deployment, validation can occur after test traffic has been re-routed and before production
  traffic has been re-routed to the 'green' ECS task set.  You can specify one or more Lambda functions in the
  deployment's AppSpec file that run during the AfterAllowTestTraffic hook. The functions can run validation tests.
  If a validation test fails, a deployment rollback is triggered. If the validation tests succeed, the next hook in
  the deployment lifecycle, BeforeAllowTraffic, is triggered.

  If a test listener is not specified, the deployment will proceed to routing the production listener to the 'green' ECS task set
  and will skip the AfterAllowTestTraffic hook.
