Skip to content
v2.274.0

EcsDeploymentGroup L2 construct ​

A CodeDeploy deployment group that orchestrates ECS blue-green deployments.

Example ​

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
# 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
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();
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
});
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(),
})

Initializer ​

ts
new EcsDeploymentGroup(scope: Construct, id: string, props: EcsDeploymentGroupProps)
python
EcsDeploymentGroup(scope: Construct, id: str, props: EcsDeploymentGroupProps)
java
new EcsDeploymentGroup(Construct scope, String id, EcsDeploymentGroupProps props)
csharp
new EcsDeploymentGroup(Construct scope, string id, EcsDeploymentGroupProps props)
go
NewEcsDeploymentGroup(Scope Construct, Id *string, Props EcsDeploymentGroupProps)

Construct Props ​

alarmsoptionalIAlarmRef[]alarmsoptionaltyping.List[IAlarmRef]alarmsoptionalList<IAlarmRef>AlarmsoptionalIAlarmRef[]Alarmsoptional*[]IAlarmRef= []#
The CloudWatch alarms associated with this Deployment Group.

CodeDeploy will stop (and optionally roll back) a deployment if during it any of the alarms trigger.

Alarms can also be added after the Deployment Group is created using the #addAlarm method.

applicationoptionalIApplicationRefapplicationoptionalIApplicationRefapplicationoptionalIApplicationRefApplicationoptionalIApplicationRefApplicationoptionalIApplicationRef#
The reference to the CodeDeploy ECS Application that this Deployment Group belongs to.

Default: One will be created for you.

autoRollbackoptionalAutoRollbackConfigauto_rollbackoptionalAutoRollbackConfigautoRollbackoptionalAutoRollbackConfigAutoRollbackoptionalAutoRollbackConfigAutoRollbackoptionalAutoRollbackConfig#
The auto-rollback configuration for this Deployment Group.

Default: default AutoRollbackConfig.

blueGreenDeploymentConfigEcsBlueGreenDeploymentConfigblue_green_deployment_configEcsBlueGreenDeploymentConfigblueGreenDeploymentConfigEcsBlueGreenDeploymentConfigBlueGreenDeploymentConfigEcsBlueGreenDeploymentConfigBlueGreenDeploymentConfigEcsBlueGreenDeploymentConfigrequired#
The configuration options for blue-green ECS deployments.
deploymentConfigoptionalIDeploymentConfigRefdeployment_configoptionalIDeploymentConfigRefdeploymentConfigoptionalIDeploymentConfigRefDeploymentConfigoptionalIDeploymentConfigRefDeploymentConfigoptionalIDeploymentConfigRef= EcsDeploymentConfig.ALL_AT_ONCE#
The Deployment Configuration this Deployment Group uses.
deploymentGroupNameoptionalstringdeployment_group_nameoptionalstrdeploymentGroupNameoptionalStringDeploymentGroupNameoptionalstringDeploymentGroupNameoptional*string#
The physical, human-readable name of the CodeDeploy Deployment Group.

Default: An auto-generated name will be used.

ignoreAlarmConfigurationoptionalbooleanignore_alarm_configurationoptionalboolignoreAlarmConfigurationoptionalBooleanIgnoreAlarmConfigurationoptionalboolIgnoreAlarmConfigurationoptional*bool= false#
Whether to skip the step of checking CloudWatch alarms during the deployment process.
ignorePollAlarmsFailureoptionalbooleanignore_poll_alarms_failureoptionalboolignorePollAlarmsFailureoptionalBooleanIgnorePollAlarmsFailureoptionalboolIgnorePollAlarmsFailureoptional*bool= false#
Whether to continue a deployment even if fetching the alarm status from CloudWatch failed.
roleoptionalIRoleroleoptionalIRoleroleoptionalIRoleRoleoptionalIRoleRoleoptionalIRole#
The service Role of this Deployment Group.

Default: A new Role will be created.

serviceIBaseServiceserviceIBaseServiceserviceIBaseServiceServiceIBaseServiceServiceIBaseServicerequired#
The ECS service to deploy with this Deployment Group.

Properties ​

applicationIEcsApplicationapplicationIEcsApplicationapplicationIEcsApplicationApplicationIEcsApplicationApplicationIEcsApplicationrequired#
The reference to the CodeDeploy ECS Application that this Deployment Group belongs to.
applicationNamestringapplication_namestrapplicationNameStringApplicationNamestringApplicationName*stringrequired#
The name of the Application.
deploymentConfigIEcsDeploymentConfigdeployment_configIEcsDeploymentConfigdeploymentConfigIEcsDeploymentConfigDeploymentConfigIEcsDeploymentConfigDeploymentConfigIEcsDeploymentConfigrequired#
The Deployment Configuration this Group uses.
deploymentGroupArnstringdeployment_group_arnstrdeploymentGroupArnStringDeploymentGroupArnstringDeploymentGroupArn*stringrequired#
The ARN of the Deployment Group.
deploymentGroupNamestringdeployment_group_namestrdeploymentGroupNameStringDeploymentGroupNamestringDeploymentGroupName*stringrequired#
The name of the Deployment Group.
deploymentGroupRefDeploymentGroupReferencedeployment_group_refDeploymentGroupReferencedeploymentGroupRefDeploymentGroupReferenceDeploymentGroupRefDeploymentGroupReferenceDeploymentGroupRefDeploymentGroupReferencerequired#
A reference to a DeploymentGroup resource.
The environment this resource belongs to.
notes

For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.

For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.

nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#
Uniquely identifies this class.
roleIRoleroleIRoleroleIRoleRoleIRoleRoleIRolerequired#
The service Role of this Deployment Group.
stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this resource is defined.

Methods ​

addAlarm(alarm: IAlarmRef): voiddef add_alarm(self, alarm: IAlarmRef) -> Nonepublic void addAlarm(IAlarmRef alarm)public void AddAlarm(IAlarmRef alarm)func AddAlarm(Alarm IAlarmRef)#
Associates an additional alarm with this Deployment Group.
1 parameter

Parameters

  • alarmalarmalarmalarmAlarm — the alarm to associate with this Deployment Group.
applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.

Parameters

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

fromEcsDeploymentGroupAttributes(scope: Construct, id: string, attrs: EcsDeploymentGroupAttributes): IEcsDeploymentGroup@staticmethod def from_ecs_deployment_group_attributes(scope: Construct, id: str, attrs: EcsDeploymentGroupAttributes) -> IEcsDeploymentGrouppublic static IEcsDeploymentGroup fromEcsDeploymentGroupAttributes(Construct scope, String id, EcsDeploymentGroupAttributes attrs)public static IEcsDeploymentGroup FromEcsDeploymentGroupAttributes(Construct scope, string id, EcsDeploymentGroupAttributes attrs)func FromEcsDeploymentGroupAttributes(Scope Construct, Id *string, Attrs EcsDeploymentGroupAttributes) IEcsDeploymentGroupstatic#
Reference an ECS Deployment Group defined outside the CDK app.

Account and region for the DeploymentGroup are taken from the application.

3 parameters · returns

Parameters

  • scopescopescopescopeScope — the parent Construct for this new Construct.
  • ididididId — the logical ID of this new Construct.
  • attrsattrsattrsattrsAttrs — the properties of the referenced Deployment Group.

Returns: a Construct representing a reference to an existing Deployment Group

isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.