From 7398f0cdce3cbdd9aea03ecac61aab351fdbf845 Mon Sep 17 00:00:00 2001 From: "k.goto" <24818752+go-to-k@users.noreply.github.com> Date: Wed, 18 Oct 2023 10:01:10 +0900 Subject: [PATCH] test(autoscaling): add tests for Schedule.cron specifying with either day or weekday (#27296) I was trying to fix [this bug](https://github.com/aws/aws-cdk/issues/27256), but [this revert PR](https://github.com/aws/aws-cdk/pull/27284) could cover it. So I added the test cases for the bug fix. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../aws-cdk-autoscaling-integ.assets.json | 6 +- .../aws-cdk-autoscaling-integ.template.json | 130 +++++++------ .../integ.custom-scaling.js.snapshot/cdk.out | 2 +- .../integ.json | 2 +- .../manifest.json | 26 +-- .../tree.json | 176 ++++++++++++------ .../test/integ.custom-scaling.ts | 10 + .../test/scheduled-action.test.ts | 55 ++++++ 8 files changed, 280 insertions(+), 127 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/aws-cdk-autoscaling-integ.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/aws-cdk-autoscaling-integ.assets.json index 6aa682503ec6e..4ca4098e56b65 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/aws-cdk-autoscaling-integ.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/aws-cdk-autoscaling-integ.assets.json @@ -1,7 +1,7 @@ { - "version": "32.0.0", + "version": "34.0.0", "files": { - "0cb946e4b3e2979f177cb049c4977a5348fa520ad7d61cddd74603bb2b06373f": { + "16290299640e9e894410b38903232b2dc97bf7a58293d69991f5518f59025aee": { "source": { "path": "aws-cdk-autoscaling-integ.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "0cb946e4b3e2979f177cb049c4977a5348fa520ad7d61cddd74603bb2b06373f.json", + "objectKey": "16290299640e9e894410b38903232b2dc97bf7a58293d69991f5518f59025aee.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-autoscaling/test/integ.custom-scaling.js.snapshot/aws-cdk-autoscaling-integ.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/aws-cdk-autoscaling-integ.template.json index ab9569a7abc85..74db358b8a940 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/aws-cdk-autoscaling-integ.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/aws-cdk-autoscaling-integ.template.json @@ -18,9 +18,6 @@ "VPCPublicSubnet1SubnetB4246D30": { "Type": "AWS::EC2::Subnet", "Properties": { - "VpcId": { - "Ref": "VPCB9E5F0B4" - }, "AvailabilityZone": { "Fn::Select": [ 0, @@ -44,21 +41,24 @@ "Key": "Name", "Value": "aws-cdk-autoscaling-integ/VPC/PublicSubnet1" } - ] + ], + "VpcId": { + "Ref": "VPCB9E5F0B4" + } } }, "VPCPublicSubnet1RouteTableFEE4B781": { "Type": "AWS::EC2::RouteTable", "Properties": { - "VpcId": { - "Ref": "VPCB9E5F0B4" - }, "Tags": [ { "Key": "Name", "Value": "aws-cdk-autoscaling-integ/VPC/PublicSubnet1" } - ] + ], + "VpcId": { + "Ref": "VPCB9E5F0B4" + } } }, "VPCPublicSubnet1RouteTableAssociation0B0896DC": { @@ -75,12 +75,12 @@ "VPCPublicSubnet1DefaultRoute91CEF279": { "Type": "AWS::EC2::Route", "Properties": { - "RouteTableId": { - "Ref": "VPCPublicSubnet1RouteTableFEE4B781" - }, "DestinationCidrBlock": "0.0.0.0/0", "GatewayId": { "Ref": "VPCIGWB7E252D3" + }, + "RouteTableId": { + "Ref": "VPCPublicSubnet1RouteTableFEE4B781" } }, "DependsOn": [ @@ -102,15 +102,15 @@ "VPCPublicSubnet1NATGatewayE0556630": { "Type": "AWS::EC2::NatGateway", "Properties": { - "SubnetId": { - "Ref": "VPCPublicSubnet1SubnetB4246D30" - }, "AllocationId": { "Fn::GetAtt": [ "VPCPublicSubnet1EIP6AD938E8", "AllocationId" ] }, + "SubnetId": { + "Ref": "VPCPublicSubnet1SubnetB4246D30" + }, "Tags": [ { "Key": "Name", @@ -126,9 +126,6 @@ "VPCPublicSubnet2Subnet74179F39": { "Type": "AWS::EC2::Subnet", "Properties": { - "VpcId": { - "Ref": "VPCB9E5F0B4" - }, "AvailabilityZone": { "Fn::Select": [ 1, @@ -152,21 +149,24 @@ "Key": "Name", "Value": "aws-cdk-autoscaling-integ/VPC/PublicSubnet2" } - ] + ], + "VpcId": { + "Ref": "VPCB9E5F0B4" + } } }, "VPCPublicSubnet2RouteTable6F1A15F1": { "Type": "AWS::EC2::RouteTable", "Properties": { - "VpcId": { - "Ref": "VPCB9E5F0B4" - }, "Tags": [ { "Key": "Name", "Value": "aws-cdk-autoscaling-integ/VPC/PublicSubnet2" } - ] + ], + "VpcId": { + "Ref": "VPCB9E5F0B4" + } } }, "VPCPublicSubnet2RouteTableAssociation5A808732": { @@ -183,12 +183,12 @@ "VPCPublicSubnet2DefaultRouteB7481BBA": { "Type": "AWS::EC2::Route", "Properties": { - "RouteTableId": { - "Ref": "VPCPublicSubnet2RouteTable6F1A15F1" - }, "DestinationCidrBlock": "0.0.0.0/0", "GatewayId": { "Ref": "VPCIGWB7E252D3" + }, + "RouteTableId": { + "Ref": "VPCPublicSubnet2RouteTable6F1A15F1" } }, "DependsOn": [ @@ -210,15 +210,15 @@ "VPCPublicSubnet2NATGateway3C070193": { "Type": "AWS::EC2::NatGateway", "Properties": { - "SubnetId": { - "Ref": "VPCPublicSubnet2Subnet74179F39" - }, "AllocationId": { "Fn::GetAtt": [ "VPCPublicSubnet2EIP4947BC00", "AllocationId" ] }, + "SubnetId": { + "Ref": "VPCPublicSubnet2Subnet74179F39" + }, "Tags": [ { "Key": "Name", @@ -234,9 +234,6 @@ "VPCPrivateSubnet1Subnet8BCA10E0": { "Type": "AWS::EC2::Subnet", "Properties": { - "VpcId": { - "Ref": "VPCB9E5F0B4" - }, "AvailabilityZone": { "Fn::Select": [ 0, @@ -260,21 +257,24 @@ "Key": "Name", "Value": "aws-cdk-autoscaling-integ/VPC/PrivateSubnet1" } - ] + ], + "VpcId": { + "Ref": "VPCB9E5F0B4" + } } }, "VPCPrivateSubnet1RouteTableBE8A6027": { "Type": "AWS::EC2::RouteTable", "Properties": { - "VpcId": { - "Ref": "VPCB9E5F0B4" - }, "Tags": [ { "Key": "Name", "Value": "aws-cdk-autoscaling-integ/VPC/PrivateSubnet1" } - ] + ], + "VpcId": { + "Ref": "VPCB9E5F0B4" + } } }, "VPCPrivateSubnet1RouteTableAssociation347902D1": { @@ -291,21 +291,18 @@ "VPCPrivateSubnet1DefaultRouteAE1D6490": { "Type": "AWS::EC2::Route", "Properties": { - "RouteTableId": { - "Ref": "VPCPrivateSubnet1RouteTableBE8A6027" - }, "DestinationCidrBlock": "0.0.0.0/0", "NatGatewayId": { "Ref": "VPCPublicSubnet1NATGatewayE0556630" + }, + "RouteTableId": { + "Ref": "VPCPrivateSubnet1RouteTableBE8A6027" } } }, "VPCPrivateSubnet2SubnetCFCDAA7A": { "Type": "AWS::EC2::Subnet", "Properties": { - "VpcId": { - "Ref": "VPCB9E5F0B4" - }, "AvailabilityZone": { "Fn::Select": [ 1, @@ -329,21 +326,24 @@ "Key": "Name", "Value": "aws-cdk-autoscaling-integ/VPC/PrivateSubnet2" } - ] + ], + "VpcId": { + "Ref": "VPCB9E5F0B4" + } } }, "VPCPrivateSubnet2RouteTable0A19E10E": { "Type": "AWS::EC2::RouteTable", "Properties": { - "VpcId": { - "Ref": "VPCB9E5F0B4" - }, "Tags": [ { "Key": "Name", "Value": "aws-cdk-autoscaling-integ/VPC/PrivateSubnet2" } - ] + ], + "VpcId": { + "Ref": "VPCB9E5F0B4" + } } }, "VPCPrivateSubnet2RouteTableAssociation0C73D413": { @@ -360,12 +360,12 @@ "VPCPrivateSubnet2DefaultRouteF4F5CFD2": { "Type": "AWS::EC2::Route", "Properties": { - "RouteTableId": { - "Ref": "VPCPrivateSubnet2RouteTable0A19E10E" - }, "DestinationCidrBlock": "0.0.0.0/0", "NatGatewayId": { "Ref": "VPCPublicSubnet2NATGateway3C070193" + }, + "RouteTableId": { + "Ref": "VPCPrivateSubnet2RouteTable0A19E10E" } } }, @@ -383,11 +383,11 @@ "VPCVPCGW99B986DC": { "Type": "AWS::EC2::VPCGatewayAttachment", "Properties": { - "VpcId": { - "Ref": "VPCB9E5F0B4" - }, "InternetGatewayId": { "Ref": "VPCIGWB7E252D3" + }, + "VpcId": { + "Ref": "VPCB9E5F0B4" } } }, @@ -516,8 +516,6 @@ "FleetASG3971DFE5": { "Type": "AWS::AutoScaling::AutoScalingGroup", "Properties": { - "MaxSize": "1", - "MinSize": "1", "LaunchTemplate": { "LaunchTemplateId": { "Ref": "FleetLaunchTemplate3FC2FEAE" @@ -529,6 +527,8 @@ ] } }, + "MaxSize": "1", + "MinSize": "1", "Tags": [ { "Key": "Name", @@ -571,6 +571,26 @@ "Recurrence": "0 20 * * *" } }, + "FleetScheduledActionScaleUpInTheDay57AE2B79": { + "Type": "AWS::AutoScaling::ScheduledAction", + "Properties": { + "AutoScalingGroupName": { + "Ref": "FleetASG3971DFE5" + }, + "MinSize": 5, + "Recurrence": "0/10 * 1 * *" + } + }, + "FleetScheduledActionScaleUpInTheWeekDay73B6B91B": { + "Type": "AWS::AutoScaling::ScheduledAction", + "Properties": { + "AutoScalingGroupName": { + "Ref": "FleetASG3971DFE5" + }, + "MinSize": 5, + "Recurrence": "0/10 * * * MON-SUN" + } + }, "FleetScalingPolicyKeepCPUReasonable89F05216": { "Type": "AWS::AutoScaling::ScalingPolicy", "Properties": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/cdk.out index f0b901e7c06e5..2313ab5436501 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/cdk.out +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/cdk.out @@ -1 +1 @@ -{"version":"32.0.0"} \ No newline at end of file +{"version":"34.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/integ.json index e5be42b4e488d..a684baca378ee 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/integ.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/integ.json @@ -1,5 +1,5 @@ { - "version": "32.0.0", + "version": "34.0.0", "testCases": { "integ.custom-scaling": { "stacks": [ diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/manifest.json index 3253890febea3..029ad9c509021 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/manifest.json @@ -1,5 +1,5 @@ { - "version": "32.0.0", + "version": "34.0.0", "artifacts": { "aws-cdk-autoscaling-integ.assets": { "type": "cdk:asset-manifest", @@ -14,10 +14,11 @@ "environment": "aws://unknown-account/unknown-region", "properties": { "templateFile": "aws-cdk-autoscaling-integ.template.json", + "terminationProtection": false, "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}/0cb946e4b3e2979f177cb049c4977a5348fa520ad7d61cddd74603bb2b06373f.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/16290299640e9e894410b38903232b2dc97bf7a58293d69991f5518f59025aee.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -213,6 +214,18 @@ "data": "FleetScheduledActionScaleDownAtNight11A03803" } ], + "/aws-cdk-autoscaling-integ/Fleet/ScheduledActionScaleUpInTheDay/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "FleetScheduledActionScaleUpInTheDay57AE2B79" + } + ], + "/aws-cdk-autoscaling-integ/Fleet/ScheduledActionScaleUpInTheWeekDay/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "FleetScheduledActionScaleUpInTheWeekDay73B6B91B" + } + ], "/aws-cdk-autoscaling-integ/Fleet/ScalingPolicyKeepCPUReasonable/Resource": [ { "type": "aws:cdk:logicalId", @@ -236,15 +249,6 @@ "type": "aws:cdk:logicalId", "data": "CheckBootstrapVersion" } - ], - "FleetLaunchTemplateProfileB169EB6D": [ - { - "type": "aws:cdk:logicalId", - "data": "FleetLaunchTemplateProfileB169EB6D", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" - ] - } ] }, "displayName": "aws-cdk-autoscaling-integ" diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/tree.json index e0be1237d1dde..a027f0bca90e3 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.js.snapshot/tree.json @@ -45,9 +45,6 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", "aws:cdk:cloudformation:props": { - "vpcId": { - "Ref": "VPCB9E5F0B4" - }, "availabilityZone": { "Fn::Select": [ 0, @@ -71,7 +68,10 @@ "key": "Name", "value": "aws-cdk-autoscaling-integ/VPC/PublicSubnet1" } - ] + ], + "vpcId": { + "Ref": "VPCB9E5F0B4" + } } }, "constructInfo": { @@ -93,15 +93,15 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", "aws:cdk:cloudformation:props": { - "vpcId": { - "Ref": "VPCB9E5F0B4" - }, "tags": [ { "key": "Name", "value": "aws-cdk-autoscaling-integ/VPC/PublicSubnet1" } - ] + ], + "vpcId": { + "Ref": "VPCB9E5F0B4" + } } }, "constructInfo": { @@ -134,12 +134,12 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Route", "aws:cdk:cloudformation:props": { - "routeTableId": { - "Ref": "VPCPublicSubnet1RouteTableFEE4B781" - }, "destinationCidrBlock": "0.0.0.0/0", "gatewayId": { "Ref": "VPCIGWB7E252D3" + }, + "routeTableId": { + "Ref": "VPCPublicSubnet1RouteTableFEE4B781" } } }, @@ -174,15 +174,15 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::NatGateway", "aws:cdk:cloudformation:props": { - "subnetId": { - "Ref": "VPCPublicSubnet1SubnetB4246D30" - }, "allocationId": { "Fn::GetAtt": [ "VPCPublicSubnet1EIP6AD938E8", "AllocationId" ] }, + "subnetId": { + "Ref": "VPCPublicSubnet1SubnetB4246D30" + }, "tags": [ { "key": "Name", @@ -212,9 +212,6 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", "aws:cdk:cloudformation:props": { - "vpcId": { - "Ref": "VPCB9E5F0B4" - }, "availabilityZone": { "Fn::Select": [ 1, @@ -238,7 +235,10 @@ "key": "Name", "value": "aws-cdk-autoscaling-integ/VPC/PublicSubnet2" } - ] + ], + "vpcId": { + "Ref": "VPCB9E5F0B4" + } } }, "constructInfo": { @@ -260,15 +260,15 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", "aws:cdk:cloudformation:props": { - "vpcId": { - "Ref": "VPCB9E5F0B4" - }, "tags": [ { "key": "Name", "value": "aws-cdk-autoscaling-integ/VPC/PublicSubnet2" } - ] + ], + "vpcId": { + "Ref": "VPCB9E5F0B4" + } } }, "constructInfo": { @@ -301,12 +301,12 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Route", "aws:cdk:cloudformation:props": { - "routeTableId": { - "Ref": "VPCPublicSubnet2RouteTable6F1A15F1" - }, "destinationCidrBlock": "0.0.0.0/0", "gatewayId": { "Ref": "VPCIGWB7E252D3" + }, + "routeTableId": { + "Ref": "VPCPublicSubnet2RouteTable6F1A15F1" } } }, @@ -341,15 +341,15 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::NatGateway", "aws:cdk:cloudformation:props": { - "subnetId": { - "Ref": "VPCPublicSubnet2Subnet74179F39" - }, "allocationId": { "Fn::GetAtt": [ "VPCPublicSubnet2EIP4947BC00", "AllocationId" ] }, + "subnetId": { + "Ref": "VPCPublicSubnet2Subnet74179F39" + }, "tags": [ { "key": "Name", @@ -379,9 +379,6 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", "aws:cdk:cloudformation:props": { - "vpcId": { - "Ref": "VPCB9E5F0B4" - }, "availabilityZone": { "Fn::Select": [ 0, @@ -405,7 +402,10 @@ "key": "Name", "value": "aws-cdk-autoscaling-integ/VPC/PrivateSubnet1" } - ] + ], + "vpcId": { + "Ref": "VPCB9E5F0B4" + } } }, "constructInfo": { @@ -427,15 +427,15 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", "aws:cdk:cloudformation:props": { - "vpcId": { - "Ref": "VPCB9E5F0B4" - }, "tags": [ { "key": "Name", "value": "aws-cdk-autoscaling-integ/VPC/PrivateSubnet1" } - ] + ], + "vpcId": { + "Ref": "VPCB9E5F0B4" + } } }, "constructInfo": { @@ -468,12 +468,12 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Route", "aws:cdk:cloudformation:props": { - "routeTableId": { - "Ref": "VPCPrivateSubnet1RouteTableBE8A6027" - }, "destinationCidrBlock": "0.0.0.0/0", "natGatewayId": { "Ref": "VPCPublicSubnet1NATGatewayE0556630" + }, + "routeTableId": { + "Ref": "VPCPrivateSubnet1RouteTableBE8A6027" } } }, @@ -498,9 +498,6 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", "aws:cdk:cloudformation:props": { - "vpcId": { - "Ref": "VPCB9E5F0B4" - }, "availabilityZone": { "Fn::Select": [ 1, @@ -524,7 +521,10 @@ "key": "Name", "value": "aws-cdk-autoscaling-integ/VPC/PrivateSubnet2" } - ] + ], + "vpcId": { + "Ref": "VPCB9E5F0B4" + } } }, "constructInfo": { @@ -546,15 +546,15 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", "aws:cdk:cloudformation:props": { - "vpcId": { - "Ref": "VPCB9E5F0B4" - }, "tags": [ { "key": "Name", "value": "aws-cdk-autoscaling-integ/VPC/PrivateSubnet2" } - ] + ], + "vpcId": { + "Ref": "VPCB9E5F0B4" + } } }, "constructInfo": { @@ -587,12 +587,12 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Route", "aws:cdk:cloudformation:props": { - "routeTableId": { - "Ref": "VPCPrivateSubnet2RouteTable0A19E10E" - }, "destinationCidrBlock": "0.0.0.0/0", "natGatewayId": { "Ref": "VPCPublicSubnet2NATGateway3C070193" + }, + "routeTableId": { + "Ref": "VPCPrivateSubnet2RouteTable0A19E10E" } } }, @@ -632,11 +632,11 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::VPCGatewayAttachment", "aws:cdk:cloudformation:props": { - "vpcId": { - "Ref": "VPCB9E5F0B4" - }, "internetGatewayId": { "Ref": "VPCIGWB7E252D3" + }, + "vpcId": { + "Ref": "VPCB9E5F0B4" } } }, @@ -762,6 +762,14 @@ "version": "0.0.0" } }, + "ImportedInstanceProfile": { + "id": "ImportedInstanceProfile", + "path": "aws-cdk-autoscaling-integ/Fleet/ImportedInstanceProfile", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, "LaunchTemplate": { "id": "LaunchTemplate", "path": "aws-cdk-autoscaling-integ/Fleet/LaunchTemplate", @@ -850,8 +858,6 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::AutoScaling::AutoScalingGroup", "aws:cdk:cloudformation:props": { - "maxSize": "1", - "minSize": "1", "launchTemplate": { "launchTemplateId": { "Ref": "FleetLaunchTemplate3FC2FEAE" @@ -863,6 +869,8 @@ ] } }, + "maxSize": "1", + "minSize": "1", "tags": [ { "key": "Name", @@ -941,6 +949,62 @@ "version": "0.0.0" } }, + "ScheduledActionScaleUpInTheDay": { + "id": "ScheduledActionScaleUpInTheDay", + "path": "aws-cdk-autoscaling-integ/Fleet/ScheduledActionScaleUpInTheDay", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-autoscaling-integ/Fleet/ScheduledActionScaleUpInTheDay/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::AutoScaling::ScheduledAction", + "aws:cdk:cloudformation:props": { + "autoScalingGroupName": { + "Ref": "FleetASG3971DFE5" + }, + "minSize": 5, + "recurrence": "0/10 * 1 * *" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_autoscaling.CfnScheduledAction", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_autoscaling.ScheduledAction", + "version": "0.0.0" + } + }, + "ScheduledActionScaleUpInTheWeekDay": { + "id": "ScheduledActionScaleUpInTheWeekDay", + "path": "aws-cdk-autoscaling-integ/Fleet/ScheduledActionScaleUpInTheWeekDay", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-autoscaling-integ/Fleet/ScheduledActionScaleUpInTheWeekDay/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::AutoScaling::ScheduledAction", + "aws:cdk:cloudformation:props": { + "autoScalingGroupName": { + "Ref": "FleetASG3971DFE5" + }, + "minSize": 5, + "recurrence": "0/10 * * * MON-SUN" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_autoscaling.CfnScheduledAction", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_autoscaling.ScheduledAction", + "version": "0.0.0" + } + }, "ScalingPolicyKeepCPUReasonable": { "id": "ScalingPolicyKeepCPUReasonable", "path": "aws-cdk-autoscaling-integ/Fleet/ScalingPolicyKeepCPUReasonable", @@ -1023,7 +1087,7 @@ "path": "Tree", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.2.55" + "version": "10.2.70" } } }, diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.ts index 58db8c47450d3..50fdf5655ff0e 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.custom-scaling.ts @@ -27,6 +27,16 @@ asg.scaleOnSchedule('ScaleDownAtNight', { maxCapacity: 2, }); +asg.scaleOnSchedule('ScaleUpInTheDay', { + schedule: autoscaling.Schedule.cron({ minute: '0/10', day: '1' }), + minCapacity: 5, +}); + +asg.scaleOnSchedule('ScaleUpInTheWeekDay', { + schedule: autoscaling.Schedule.cron({ minute: '0/10', weekDay: 'MON-SUN' }), + minCapacity: 5, +}); + asg.scaleOnCpuUtilization('KeepCPUReasonable', { targetUtilizationPercent: 50, }); diff --git a/packages/aws-cdk-lib/aws-autoscaling/test/scheduled-action.test.ts b/packages/aws-cdk-lib/aws-autoscaling/test/scheduled-action.test.ts index 943939c09febb..a1192d003acd5 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/test/scheduled-action.test.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/test/scheduled-action.test.ts @@ -168,6 +168,61 @@ describeDeprecated('scheduled action', () => { expect(action.scheduledActionName).toBeDefined(); }); + + test('scheduled scaling shows no warning when day is specified and weekDay is undefined in cron', () => { + // GIVEN + const stack = new cdk.Stack(); + const asg = makeAutoScalingGroup(stack); + + // WHEN + asg.scaleOnSchedule('ScaleOutInTheMorning', { + schedule: autoscaling.Schedule.cron({ + minute: '0/10', + day: '1', + }), + minCapacity: 10, + }); + + // THEN + const annotations = Annotations.fromStack(stack).findWarning('*', Match.anyValue()); + expect(annotations.length).toBe(0); + }); + + test('scheduled scaling shows no warning when weekDay is specified and day is undefined in cron', () => { + // GIVEN + const stack = new cdk.Stack(); + const asg = makeAutoScalingGroup(stack); + + // WHEN + asg.scaleOnSchedule('ScaleOutInTheMorning', { + schedule: autoscaling.Schedule.cron({ + minute: '0/10', + weekDay: 'MON-SUN', + }), + minCapacity: 10, + }); + + // THEN + const annotations = Annotations.fromStack(stack).findWarning('*', Match.anyValue()); + expect(annotations.length).toBe(0); + }); + + test('throws when both day and weekDay are specified in cron', () => { + // GIVEN + const stack = new cdk.Stack(); + const asg = makeAutoScalingGroup(stack); + + // WHEN + // THEN + expect(() => asg.scaleOnSchedule('ScaleOutInTheMorning', { + schedule: autoscaling.Schedule.cron({ + minute: '0/10', + day: '1', + weekDay: 'MON-SUN', + }), + minCapacity: 10, + })).toThrowError(/Cannot supply both \'day\' and \'weekDay\', use at most one/); + }); }); function makeAutoScalingGroup(scope: constructs.Construct) {