From b799c82526b755d3f6005fd022467d7dcb220bb3 Mon Sep 17 00:00:00 2001 From: Tatsuya Mori Date: Wed, 12 Jul 2023 20:13:29 +0900 Subject: [PATCH] fix(ecs): DeploymentAlarms property is specified for ECS service with CODE_DEPLOY and EXTERNAL deployment controller (#26317) From #25840, ECS L2 construct sets the default configuration for the `CfnService.deploymentConfiguration.alarms` property to: ``` alarmNames: [], rollback: false, enable: false, ``` However, alarm based rollback feature is only supported for ECS services that use the rolling update (ECS) deployment controller. https://docs.aws.amazon.com/AmazonECS/latest/developerguide/deployment-alarm-failure.html Due to this limitation, when deploymentController is set to CODE_DEPLOY or EXTERNAL, creation for the service will fail by conflict with `deploymentConfiguration.alarms` property. This PR solves the issue by skipping to set default configuration for the `CfnService.deploymentConfiguration.alarms` property for CODE_DEPLOY and EXTERNAL deployment controller. Closes #26307 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../aws-cdk-codedeploy-ecs-dg.assets.json | 4 +- .../aws-cdk-codedeploy-ecs-dg.template.json | 5 - .../manifest.json | 2 +- .../tree.json | 383 +++++++++--------- .../aws-ecs/lib/base/base-service.ts | 4 +- .../aws-ecs/test/base-service.test.ts | 125 ++++++ 6 files changed, 320 insertions(+), 203 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-codedeploy/test/ecs/integ.deployment-group.js.snapshot/aws-cdk-codedeploy-ecs-dg.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-codedeploy/test/ecs/integ.deployment-group.js.snapshot/aws-cdk-codedeploy-ecs-dg.assets.json index dcf68b157c2b9..a0b1b02ba7950 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-codedeploy/test/ecs/integ.deployment-group.js.snapshot/aws-cdk-codedeploy-ecs-dg.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codedeploy/test/ecs/integ.deployment-group.js.snapshot/aws-cdk-codedeploy-ecs-dg.assets.json @@ -1,7 +1,7 @@ { "version": "32.0.0", "files": { - "146a3a0178544a80f025b470e820a77ec783a43b2a5ae0a2590037423ed16a6b": { + "54ea34edd18b9383781f88fd1ab5487b7d2a4ca076f0a365fa77e3b3a4b109d9": { "source": { "path": "aws-cdk-codedeploy-ecs-dg.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "146a3a0178544a80f025b470e820a77ec783a43b2a5ae0a2590037423ed16a6b.json", + "objectKey": "54ea34edd18b9383781f88fd1ab5487b7d2a4ca076f0a365fa77e3b3a4b109d9.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-codedeploy/test/ecs/integ.deployment-group.js.snapshot/aws-cdk-codedeploy-ecs-dg.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-codedeploy/test/ecs/integ.deployment-group.js.snapshot/aws-cdk-codedeploy-ecs-dg.template.json index db8c35d037078..64f48e53ec831 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-codedeploy/test/ecs/integ.deployment-group.js.snapshot/aws-cdk-codedeploy-ecs-dg.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codedeploy/test/ecs/integ.deployment-group.js.snapshot/aws-cdk-codedeploy-ecs-dg.template.json @@ -449,11 +449,6 @@ "Ref": "EcsCluster97242B84" }, "DeploymentConfiguration": { - "Alarms": { - "AlarmNames": [], - "Enable": false, - "Rollback": false - }, "MaximumPercent": 200, "MinimumHealthyPercent": 50 }, diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-codedeploy/test/ecs/integ.deployment-group.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-codedeploy/test/ecs/integ.deployment-group.js.snapshot/manifest.json index a5ae2431ff982..2ac61ce54d5a8 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-codedeploy/test/ecs/integ.deployment-group.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codedeploy/test/ecs/integ.deployment-group.js.snapshot/manifest.json @@ -17,7 +17,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/146a3a0178544a80f025b470e820a77ec783a43b2a5ae0a2590037423ed16a6b.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/54ea34edd18b9383781f88fd1ab5487b7d2a4ca076f0a365fa77e3b3a4b109d9.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-codedeploy/test/ecs/integ.deployment-group.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-codedeploy/test/ecs/integ.deployment-group.js.snapshot/tree.json index c374cae635fe2..b5cdc1e7eed0e 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-codedeploy/test/ecs/integ.deployment-group.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-codedeploy/test/ecs/integ.deployment-group.js.snapshot/tree.json @@ -31,8 +31,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnVPC", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "PublicSubnet1": { @@ -75,16 +75,16 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "Acl": { "id": "Acl", "path": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1/Acl", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "RouteTable": { @@ -105,8 +105,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "RouteTableAssociation": { @@ -124,8 +124,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "DefaultRoute": { @@ -144,8 +144,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "EIP": { @@ -164,8 +164,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnEIP", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "NATGateway": { @@ -192,14 +192,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnNatGateway", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.PublicSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "PublicSubnet2": { @@ -242,16 +242,16 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "Acl": { "id": "Acl", "path": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2/Acl", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "RouteTable": { @@ -272,8 +272,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "RouteTableAssociation": { @@ -291,8 +291,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "DefaultRoute": { @@ -311,8 +311,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "EIP": { @@ -331,8 +331,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnEIP", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "NATGateway": { @@ -359,14 +359,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnNatGateway", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.PublicSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "PrivateSubnet1": { @@ -409,16 +409,16 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "Acl": { "id": "Acl", "path": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet1/Acl", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "RouteTable": { @@ -439,8 +439,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "RouteTableAssociation": { @@ -458,8 +458,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "DefaultRoute": { @@ -478,14 +478,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.PrivateSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "PrivateSubnet2": { @@ -528,16 +528,16 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "Acl": { "id": "Acl", "path": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet2/Acl", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "RouteTable": { @@ -558,8 +558,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "RouteTableAssociation": { @@ -577,8 +577,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "DefaultRoute": { @@ -597,14 +597,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.PrivateSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "IGW": { @@ -622,8 +622,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnInternetGateway", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "VPCGW": { @@ -641,14 +641,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnVPCGatewayAttachment", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.Vpc", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "EcsCluster": { @@ -663,14 +663,14 @@ "aws:cdk:cloudformation:props": {} }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ecs.CfnCluster", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ecs.Cluster", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "TaskDef": { @@ -685,8 +685,8 @@ "id": "ImportTaskRole", "path": "aws-cdk-codedeploy-ecs-dg/TaskDef/TaskRole/ImportTaskRole", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "Resource": { @@ -710,14 +710,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.CfnRole", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.Role", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "Resource": { @@ -755,22 +755,22 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ecs.CfnTaskDefinition", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "Container": { "id": "Container", "path": "aws-cdk-codedeploy-ecs-dg/TaskDef/Container", "constructInfo": { - "fqn": "aws-cdk-lib.aws_ecs.ContainerDefinition", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ecs.FargateTaskDefinition", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "FargateService": { @@ -788,12 +788,7 @@ }, "deploymentConfiguration": { "maximumPercent": 200, - "minimumHealthyPercent": 50, - "alarms": { - "alarmNames": [], - "enable": false, - "rollback": false - } + "minimumHealthyPercent": 50 }, "deploymentController": { "type": "CODE_DEPLOY" @@ -835,8 +830,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ecs.CfnService", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "SecurityGroup": { @@ -863,8 +858,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSecurityGroup", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "from awscdkcodedeployecsdgServiceLBSecurityGroupEC967688:80": { @@ -892,20 +887,20 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSecurityGroupIngress", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.SecurityGroup", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ecs.FargateService", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "TaskDef2": { @@ -920,8 +915,8 @@ "id": "ImportTaskRole", "path": "aws-cdk-codedeploy-ecs-dg/TaskDef2/TaskRole/ImportTaskRole", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "Resource": { @@ -945,14 +940,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.CfnRole", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.Role", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "Resource": { @@ -990,22 +985,22 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ecs.CfnTaskDefinition", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "Container": { "id": "Container", "path": "aws-cdk-codedeploy-ecs-dg/TaskDef2/Container", "constructInfo": { - "fqn": "aws-cdk-lib.aws_ecs.ContainerDefinition", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ecs.FargateTaskDefinition", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "ServiceLB": { @@ -1045,8 +1040,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_elasticloadbalancingv2.CfnLoadBalancer", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "SecurityGroup": { @@ -1082,8 +1077,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSecurityGroup", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "to awscdkcodedeployecsdgFargateServiceSecurityGroup64C2B62E:80": { @@ -1111,14 +1106,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSecurityGroupEgress", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.SecurityGroup", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "ProdListener": { @@ -1147,8 +1142,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_elasticloadbalancingv2.CfnListener", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "BlueTGGroup": { @@ -1187,20 +1182,20 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_elasticloadbalancingv2.CfnTargetGroup", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_elasticloadbalancingv2.ApplicationTargetGroup", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_elasticloadbalancingv2.ApplicationListener", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "TestListener": { @@ -1229,20 +1224,20 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_elasticloadbalancingv2.CfnListener", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_elasticloadbalancingv2.ApplicationListener", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_elasticloadbalancingv2.ApplicationLoadBalancer", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "GreenTG": { @@ -1281,14 +1276,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_elasticloadbalancingv2.CfnTargetGroup", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_elasticloadbalancingv2.ApplicationTargetGroup", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "BlueUnhealthyHosts": { @@ -1374,14 +1369,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_cloudwatch.CfnAlarm", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_cloudwatch.Alarm", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "Blue5xx": { @@ -1467,14 +1462,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_cloudwatch.CfnAlarm", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_cloudwatch.Alarm", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "GreenUnhealthyHosts": { @@ -1560,14 +1555,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_cloudwatch.CfnAlarm", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_cloudwatch.Alarm", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "Green5xx": { @@ -1653,14 +1648,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_cloudwatch.CfnAlarm", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_cloudwatch.Alarm", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "CanaryConfig": { @@ -1684,14 +1679,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_codedeploy.CfnDeploymentConfig", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_codedeploy.EcsDeploymentConfig", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "BlueGreenDG": { @@ -1706,8 +1701,8 @@ "id": "ImportServiceRole", "path": "aws-cdk-codedeploy-ecs-dg/BlueGreenDG/ServiceRole/ImportServiceRole", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "Resource": { @@ -1745,14 +1740,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.CfnRole", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.Role", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "Application": { @@ -1769,14 +1764,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_codedeploy.CfnApplication", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_codedeploy.EcsApplication", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "Resource": { @@ -1898,84 +1893,84 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_codedeploy.CfnDeploymentGroup", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_codedeploy.EcsDeploymentGroup", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "NewTaskDefinition": { "id": "NewTaskDefinition", "path": "aws-cdk-codedeploy-ecs-dg/NewTaskDefinition", "constructInfo": { - "fqn": "aws-cdk-lib.CfnOutput", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "Subnet1Id": { "id": "Subnet1Id", "path": "aws-cdk-codedeploy-ecs-dg/Subnet1Id", "constructInfo": { - "fqn": "aws-cdk-lib.CfnOutput", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "Subnet2Id": { "id": "Subnet2Id", "path": "aws-cdk-codedeploy-ecs-dg/Subnet2Id", "constructInfo": { - "fqn": "aws-cdk-lib.CfnOutput", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "SecurityGroupId": { "id": "SecurityGroupId", "path": "aws-cdk-codedeploy-ecs-dg/SecurityGroupId", "constructInfo": { - "fqn": "aws-cdk-lib.CfnOutput", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "CodeDeployApplicationName": { "id": "CodeDeployApplicationName", "path": "aws-cdk-codedeploy-ecs-dg/CodeDeployApplicationName", "constructInfo": { - "fqn": "aws-cdk-lib.CfnOutput", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "CodeDeployDeploymentGroupName": { "id": "CodeDeployDeploymentGroupName", "path": "aws-cdk-codedeploy-ecs-dg/CodeDeployDeploymentGroupName", "constructInfo": { - "fqn": "aws-cdk-lib.CfnOutput", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "BootstrapVersion": { "id": "BootstrapVersion", "path": "aws-cdk-codedeploy-ecs-dg/BootstrapVersion", "constructInfo": { - "fqn": "aws-cdk-lib.CfnParameter", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "CheckBootstrapVersion": { "id": "CheckBootstrapVersion", "path": "aws-cdk-codedeploy-ecs-dg/CheckBootstrapVersion", "constructInfo": { - "fqn": "aws-cdk-lib.CfnRule", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.Stack", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "EcsDeploymentGroupTest": { @@ -2002,22 +1997,22 @@ "id": "BootstrapVersion", "path": "EcsDeploymentGroupTest/DefaultTest/DeployAssert/BootstrapVersion", "constructInfo": { - "fqn": "aws-cdk-lib.CfnParameter", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } }, "CheckBootstrapVersion": { "id": "CheckBootstrapVersion", "path": "EcsDeploymentGroupTest/DefaultTest/DeployAssert/CheckBootstrapVersion", "constructInfo": { - "fqn": "aws-cdk-lib.CfnRule", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.Stack", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } }, @@ -2042,8 +2037,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.App", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.2.55" } } } \ No newline at end of file diff --git a/packages/aws-cdk-lib/aws-ecs/lib/base/base-service.ts b/packages/aws-cdk-lib/aws-ecs/lib/base/base-service.ts index 1631c019e24b1..05a0054491554 100644 --- a/packages/aws-cdk-lib/aws-ecs/lib/base/base-service.ts +++ b/packages/aws-cdk-lib/aws-ecs/lib/base/base-service.ts @@ -682,7 +682,9 @@ export abstract class BaseService extends Resource enable: true, rollback: props.deploymentAlarms.behavior !== AlarmBehavior.FAIL_ON_ALARM, }; - } else if (this.deploymentAlarmsAvailableInRegion()) { + // CloudWatch alarms is only supported for Amazon ECS services that use the rolling update (ECS) deployment controller. + } else if ((!props.deploymentController || + props.deploymentController?.type === DeploymentControllerType.ECS) && this.deploymentAlarmsAvailableInRegion()) { this.deploymentAlarms = { alarmNames: [], enable: false, diff --git a/packages/aws-cdk-lib/aws-ecs/test/base-service.test.ts b/packages/aws-cdk-lib/aws-ecs/test/base-service.test.ts index b9a52a0b646b8..b1cda7643a844 100644 --- a/packages/aws-cdk-lib/aws-ecs/test/base-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs/test/base-service.test.ts @@ -75,6 +75,131 @@ describe('When import an ECS Service', () => { }); }); +describe('For alarm-based rollbacks', () => { + let stack: cdk.Stack; + + beforeEach(() => { + stack = new cdk.Stack(); + }); + + test('deploymentAlarms is set by default for ECS deployment controller', () => { + // GIVEN + const vpc = new ec2.Vpc(stack, 'Vpc'); + const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); + const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef'); + taskDefinition.addContainer('web', { + image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), + }); + + // WHEN + new ecs.FargateService(stack, 'FargateService', { + cluster, + taskDefinition, + deploymentController: { + type: ecs.DeploymentControllerType.ECS, + }, + minHealthyPercent: 100, + maxHealthyPercent: 200, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { + DeploymentConfiguration: { + Alarms: { + AlarmNames: [], + Enable: false, + Rollback: false, + }, + }, + }); + }); + + test('deploymentAlarms is set by default when deployment controller is not specified', () => { + // GIVEN + const vpc = new ec2.Vpc(stack, 'Vpc'); + const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); + const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef'); + taskDefinition.addContainer('web', { + image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), + }); + + // WHEN + new ecs.FargateService(stack, 'FargateService', { + cluster, + taskDefinition, + minHealthyPercent: 100, + maxHealthyPercent: 200, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { + DeploymentConfiguration: { + Alarms: { + AlarmNames: [], + Enable: false, + Rollback: false, + }, + }, + }); + }); + + test('should omit deploymentAlarms for CodeDeploy deployment controller', () => { + // GIVEN + const vpc = new ec2.Vpc(stack, 'Vpc'); + const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); + const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef'); + taskDefinition.addContainer('web', { + image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), + }); + + // WHEN + new ecs.FargateService(stack, 'FargateService', { + cluster, + taskDefinition, + deploymentController: { + type: ecs.DeploymentControllerType.CODE_DEPLOY, + }, + minHealthyPercent: 100, + maxHealthyPercent: 200, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { + DeploymentConfiguration: { + Alarms: Match.absent(), + }, + }); + }); + + test('should omit deploymentAlarms for External deployment controller', () => { + // GIVEN + const vpc = new ec2.Vpc(stack, 'Vpc'); + const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); + const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef'); + taskDefinition.addContainer('web', { + image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), + }); + + // WHEN + new ecs.FargateService(stack, 'FargateService', { + cluster, + taskDefinition, + deploymentController: { + type: ecs.DeploymentControllerType.EXTERNAL, + }, + minHealthyPercent: 100, + maxHealthyPercent: 200, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { + DeploymentConfiguration: { + Alarms: Match.absent(), + }, + }); + }); +}); + test.each([ /* breaker, flag => controller in template */ /* Flag off => value present if circuitbreaker */