Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(autoscaling): support default instance warmup for Auto Scaling groups #23285

Merged
merged 16 commits into from Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts
Expand Up @@ -336,6 +336,18 @@ export interface CommonAutoScalingGroupProps {
* @default - `TerminationPolicy.DEFAULT`
*/
readonly terminationPolicies?: TerminationPolicy[];

/**
* The amount of time, in seconds, until a newly launched instance can contribute to the Amazon CloudWatch metrics.
* This delay lets an instance finish initializing before Amazon EC2 Auto Scaling aggregates instance metrics,
* resulting in more reliable usage data. Set this value equal to the amount of time that it takes for resource
* consumption to become stable after an instance reaches the InService state.
*
* @see https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-default-instance-warmup.html
*
* @default Duration.seconds(0)
*/
readonly defaultInstanceWarmup?: Duration;
}

/**
Expand Down Expand Up @@ -1344,6 +1356,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements
maxInstanceLifetime: this.maxInstanceLifetime ? this.maxInstanceLifetime.toSeconds() : undefined,
newInstancesProtectedFromScaleIn: Lazy.any({ produce: () => this.newInstancesProtectedFromScaleIn }),
terminationPolicies: props.terminationPolicies,
defaultInstanceWarmup: props.defaultInstanceWarmup?.toSeconds(),
...this.getLaunchSettings(launchConfig, props.launchTemplate, props.mixedInstancesPolicy),
};

Expand Down
@@ -1,15 +1,15 @@
{
"version": "21.0.0",
"version": "22.0.0",
"files": {
"2ca8f144c3e288148d58c9b9e86c9034f6a72b09cecffac3a5d406f8f53d5b18": {
"768b8ff8b1178a04dbfca488da9459f4f402bfad643db0b4791787ef23ec4db5": {
"source": {
"path": "aws-cdk-asg-integ.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "2ca8f144c3e288148d58c9b9e86c9034f6a72b09cecffac3a5d406f8f53d5b18.json",
"objectKey": "768b8ff8b1178a04dbfca488da9459f4f402bfad643db0b4791787ef23ec4db5.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Expand Up @@ -507,6 +507,38 @@
}
}
},
"AsgWithDefaultInstanceWarmupASG7A481C66": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"MaxSize": "1",
"MinSize": "1",
"DefaultInstanceWarmup": 5,
"LaunchTemplate": {
"LaunchTemplateId": {
"Ref": "MainLT4FC09097"
},
"Version": {
"Fn::GetAtt": [
"MainLT4FC09097",
"LatestVersionNumber"
]
}
},
"VPCZoneIdentifier": [
{
"Ref": "VPCPrivateSubnet1Subnet8BCA10E0"
},
{
"Ref": "VPCPrivateSubnet2SubnetCFCDAA7A"
}
]
},
"UpdatePolicy": {
"AutoScalingScheduledAction": {
"IgnoreUnmodifiedGroupSizeProperties": true
}
}
},
"AsgFromMipASG9EFCE2FC": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
Expand Down
@@ -1 +1 @@
{"version":"21.0.0"}
{"version":"22.0.0"}
@@ -1,5 +1,5 @@
{
"version": "21.0.0",
"version": "22.0.0",
"testCases": {
"integ.asg-lt": {
"stacks": [
Expand Down
@@ -1,12 +1,6 @@
{
"version": "21.0.0",
"version": "22.0.0",
"artifacts": {
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
},
"aws-cdk-asg-integ.assets": {
"type": "cdk:asset-manifest",
"properties": {
Expand All @@ -23,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}/2ca8f144c3e288148d58c9b9e86c9034f6a72b09cecffac3a5d406f8f53d5b18.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/768b8ff8b1178a04dbfca488da9459f4f402bfad643db0b4791787ef23ec4db5.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down Expand Up @@ -213,6 +207,12 @@
"data": "AsgFromLTASG089B7C3A"
}
],
"/aws-cdk-asg-integ/AsgWithDefaultInstanceWarmup/ASG": [
{
"type": "aws:cdk:logicalId",
"data": "AsgWithDefaultInstanceWarmupASG7A481C66"
}
],
"/aws-cdk-asg-integ/AsgFromMip": [
{
"type": "aws:cdk:warning",
Expand Down Expand Up @@ -293,6 +293,12 @@
]
},
"displayName": "aws-cdk-asg-integ"
},
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
}
}
}
Expand Up @@ -4,14 +4,6 @@
"id": "App",
"path": "",
"children": {
"Tree": {
"id": "Tree",
"path": "Tree",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.1.140"
}
},
"aws-cdk-asg-integ": {
"id": "aws-cdk-asg-integ",
"path": "aws-cdk-asg-integ",
Expand Down Expand Up @@ -856,6 +848,51 @@
"version": "0.0.0"
}
},
"AsgWithDefaultInstanceWarmup": {
"id": "AsgWithDefaultInstanceWarmup",
"path": "aws-cdk-asg-integ/AsgWithDefaultInstanceWarmup",
"children": {
"ASG": {
"id": "ASG",
"path": "aws-cdk-asg-integ/AsgWithDefaultInstanceWarmup/ASG",
"attributes": {
"aws:cdk:cloudformation:type": "AWS::AutoScaling::AutoScalingGroup",
"aws:cdk:cloudformation:props": {
"maxSize": "1",
"minSize": "1",
"defaultInstanceWarmup": 5,
"launchTemplate": {
"launchTemplateId": {
"Ref": "MainLT4FC09097"
},
"version": {
"Fn::GetAtt": [
"MainLT4FC09097",
"LatestVersionNumber"
]
}
},
"vpcZoneIdentifier": [
{
"Ref": "VPCPrivateSubnet1Subnet8BCA10E0"
},
{
"Ref": "VPCPrivateSubnet2SubnetCFCDAA7A"
}
]
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-autoscaling.CfnAutoScalingGroup",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-autoscaling.AutoScalingGroup",
"version": "0.0.0"
}
},
"AsgFromMip": {
"id": "AsgFromMip",
"path": "aws-cdk-asg-integ/AsgFromMip",
Expand Down Expand Up @@ -1049,6 +1086,14 @@
"id": "InstanceRole",
"path": "aws-cdk-asg-integ/AsgWithGp3Blockdevice/InstanceRole",
"children": {
"ImportInstanceRole": {
"id": "ImportInstanceRole",
"path": "aws-cdk-asg-integ/AsgWithGp3Blockdevice/InstanceRole/ImportInstanceRole",
"constructInfo": {
"fqn": "@aws-cdk/core.Resource",
"version": "0.0.0"
}
},
"Resource": {
"id": "Resource",
"path": "aws-cdk-asg-integ/AsgWithGp3Blockdevice/InstanceRole/Resource",
Expand Down Expand Up @@ -1202,12 +1247,36 @@
"fqn": "@aws-cdk/core.Resource",
"version": "0.0.0"
}
},
"BootstrapVersion": {
"id": "BootstrapVersion",
"path": "aws-cdk-asg-integ/BootstrapVersion",
"constructInfo": {
"fqn": "@aws-cdk/core.CfnParameter",
"version": "0.0.0"
}
},
"CheckBootstrapVersion": {
"id": "CheckBootstrapVersion",
"path": "aws-cdk-asg-integ/CheckBootstrapVersion",
"constructInfo": {
"fqn": "@aws-cdk/core.CfnRule",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/core.Stack",
"version": "0.0.0"
}
},
"Tree": {
"id": "Tree",
"path": "Tree",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.1.168"
}
}
},
"constructInfo": {
Expand Down
6 changes: 6 additions & 0 deletions packages/@aws-cdk/aws-autoscaling/test/integ.asg-lt.ts
Expand Up @@ -34,6 +34,12 @@ new autoscaling.AutoScalingGroup(stack, 'AsgFromLT', {
desiredCapacity: 5,
});

new autoscaling.AutoScalingGroup(stack, 'AsgWithDefaultInstanceWarmup', {
vpc,
launchTemplate: lt,
defaultInstanceWarmup: cdk.Duration.seconds(5),
});

new autoscaling.AutoScalingGroup(stack, 'AsgFromMip', {
vpc,
mixedInstancesPolicy: {
Expand Down