Skip to content

Commit

Permalink
change parameter name
Browse files Browse the repository at this point in the history
  • Loading branch information
go-to-k committed Nov 25, 2023
1 parent 23ef1b7 commit 5eb173e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ new autoscaling.AutoScalingGroup(stack, 'ASG', {
vpc,
instanceType: new ec2.InstanceType('t2.micro'),
machineImage: new ec2.AmazonLinuxImage({ generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2 }),
maintenancePolicyMaxHealthPercentage: 200,
maintenancePolicyMinHealthPercentage: 100,
instanceMaintenancePolicyMaxHealthPercentage: 200,
instanceMaintenancePolicyMinHealthPercentage: 100,
});

new integ.IntegTest(app, 'InstanceMaintenancePolicyTest', {
Expand Down
10 changes: 5 additions & 5 deletions packages/aws-cdk-lib/aws-autoscaling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ can make sure that Amazon EC2 Auto Scaling first launches a new instance and the
it to be fully ready before terminating the unhealthy instance.

An instance maintenance policy also helps you minimize any potential disruptions in cases where
multiple instances are replaced at the same time. You set the `maintenancePolicyMinHealthPercentage`
and the `maintenancePolicyMaxHealthPercentage` for the policy, and your Auto Scaling group can only
increase and decrease capacity within that minimum-maximum range when replacing instances.
multiple instances are replaced at the same time. You set the `instanceMaintenancePolicyMinHealthPercentage`
and the `instanceMaintenancePolicyMaxHealthPercentage` for the policy, and your Auto Scaling group
can only increase and decrease capacity within that minimum-maximum range when replacing instances.
A larger range increases the number of instances that can be replaced at the same time.

```ts
Expand All @@ -313,8 +313,8 @@ new autoscaling.AutoScalingGroup(this, 'ASG', {
vpc,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO),
machineImage: ec2.MachineImage.latestAmazonLinux2(),
maintenancePolicyMaxHealthPercentage: 200,
maintenancePolicyMinHealthPercentage: 100,
instanceMaintenancePolicyMaxHealthPercentage: 200,
instanceMaintenancePolicyMinHealthPercentage: 100,
});
```

Expand Down
30 changes: 15 additions & 15 deletions packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,36 +692,36 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps {
* It represents the maximum percentage of the group that can be in service and healthy, or pending,
* to support your workload when replacing instances.
*
* Value range is 0 to 100. After it's set, both `maintenancePolicyMinHealthPercentage` and
* `maintenancePolicyMaxHealthPercentage` to -1 will clear the previously set value.
* Value range is 0 to 100. After it's set, both `instanceMaintenancePolicyMinHealthPercentage` and
* `instanceMaintenancePolicyMaxHealthPercentage` to -1 will clear the previously set value.
*
* Both or neither of `maintenancePolicyMinHealthPercentage` and `maintenancePolicyMaxHealthPercentage`
* Both or neither of `instanceMaintenancePolicyMinHealthPercentage` and `instanceMaintenancePolicyMaxHealthPercentage`
* must be specified, and the difference between them cannot be greater than 100. A large range increases
* the number of instances that can be replaced at the same time.
*
* @see https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-instance-maintenance-policy.html
*
* @default - Do not provide percentage.
*/
readonly maintenancePolicyMaxHealthPercentage?: number;
readonly instanceMaintenancePolicyMaxHealthPercentage?: number;

/**
* Specifies the lower threshold as a percentage of the desired capacity of the Auto Scaling group.
* It represents the minimum percentage of the group to keep in service, healthy, and ready to use
* to support your workload when replacing instances.
*
* Value range is 0 to 100. After it's set, both `maintenancePolicyMinHealthPercentage` and
* `maintenancePolicyMaxHealthPercentage` to -1 will clear the previously set value.
* Value range is 0 to 100. After it's set, both `instanceMaintenancePolicyMinHealthPercentage` and
* `instanceMaintenancePolicyMaxHealthPercentage` to -1 will clear the previously set value.
*
* Both or neither of `maintenancePolicyMinHealthPercentage` and `maintenancePolicyMaxHealthPercentage`
* Both or neither of `instanceMaintenancePolicyMinHealthPercentage` and `instanceMaintenancePolicyMaxHealthPercentage`
* must be specified, and the difference between them cannot be greater than 100. A large range increases
* the number of instances that can be replaced at the same time.
*
* @see https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-instance-maintenance-policy.html
*
* @default - Do not provide percentage.
*/
readonly maintenancePolicyMinHealthPercentage?: number;
readonly instanceMaintenancePolicyMinHealthPercentage?: number;
}

/**
Expand Down Expand Up @@ -1464,8 +1464,8 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements
defaultInstanceWarmup: props.defaultInstanceWarmup?.toSeconds(),
capacityRebalance: props.capacityRebalance,
instanceMaintenancePolicy: this.renderInstanceMaintenancePolicy(
props.maintenancePolicyMaxHealthPercentage,
props.maintenancePolicyMinHealthPercentage,
props.instanceMaintenancePolicyMaxHealthPercentage,
props.instanceMaintenancePolicyMinHealthPercentage,
),
...this.getLaunchSettings(launchConfig, props.launchTemplate ?? launchTemplateFromConfig, props.mixedInstancesPolicy),
};
Expand Down Expand Up @@ -1893,16 +1893,16 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements
(maxHealthPercentage !== undefined && minHealthPercentage === undefined)
|| (maxHealthPercentage === undefined && minHealthPercentage !== undefined)
) {
throw new Error(`Both or neither of maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be specified, got maintenancePolicyMinHealthPercentage: ${minHealthPercentage} and maintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`);
throw new Error(`Both or neither of instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage must be specified, got instanceMaintenancePolicyMinHealthPercentage: ${minHealthPercentage} and instanceMaintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`);
}
if ((maxHealthPercentage !== -1 && minHealthPercentage === -1) || (maxHealthPercentage === -1 && minHealthPercentage !== -1)) {
throw new Error(`Both maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got maintenancePolicyMinHealthPercentage: ${minHealthPercentage} and maintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`);
throw new Error(`Both instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got instanceMaintenancePolicyMinHealthPercentage: ${minHealthPercentage} and instanceMaintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`);
}
if (maxHealthPercentage !== undefined && maxHealthPercentage !== -1 && (maxHealthPercentage < 100 || maxHealthPercentage > 200)) {
throw new Error(`maintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got ${maxHealthPercentage}`);
throw new Error(`instanceMaintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got ${maxHealthPercentage}`);
}
if (minHealthPercentage !== undefined && minHealthPercentage !== -1 && (minHealthPercentage < 0 || minHealthPercentage > 100)) {
throw new Error(`maintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got ${minHealthPercentage}`);
throw new Error(`instanceMaintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got ${minHealthPercentage}`);
}
if (
maxHealthPercentage !== undefined
Expand All @@ -1911,7 +1911,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements
&& minHealthPercentage !== -1
&& maxHealthPercentage - minHealthPercentage > 100
) {
throw new Error(`The difference between maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage cannot be greater than 100, got ${maxHealthPercentage - minHealthPercentage}`);
throw new Error(`The difference between instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage cannot be greater than 100, got ${maxHealthPercentage - minHealthPercentage}`);
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2404,16 +2404,16 @@ test('requires imdsv2 when @aws-cdk/aws-autoscaling:generateLaunchTemplateInstea
});

describe('InstanceMaintenancePolicy', () => {
test('maintenancePolicyMaxHealthPercentage and maintenancePolicyMinHealthPercentage can be specified', () => {
test('instanceMaintenancePolicyMaxHealthPercentage and instanceMaintenancePolicyMinHealthPercentage can be specified', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = mockVpc(stack);
new autoscaling.AutoScalingGroup(stack, 'ASG', {
vpc,
instanceType: new ec2.InstanceType('t2.micro'),
machineImage: ec2.MachineImage.latestAmazonLinux2(),
maintenancePolicyMaxHealthPercentage: 200,
maintenancePolicyMinHealthPercentage: 100,
instanceMaintenancePolicyMaxHealthPercentage: 200,
instanceMaintenancePolicyMinHealthPercentage: 100,
});

// Then
Expand All @@ -2425,16 +2425,16 @@ describe('InstanceMaintenancePolicy', () => {
});
});

test('maintenancePolicyMaxHealthPercentage and maintenancePolicyMinHealthPercentage can be set to -1', () => {
test('instanceMaintenancePolicyMaxHealthPercentage and instanceMaintenancePolicyMinHealthPercentage can be set to -1', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = mockVpc(stack);
new autoscaling.AutoScalingGroup(stack, 'ASG', {
vpc,
instanceType: new ec2.InstanceType('t2.micro'),
machineImage: ec2.MachineImage.latestAmazonLinux2(),
maintenancePolicyMaxHealthPercentage: -1,
maintenancePolicyMinHealthPercentage: -1,
instanceMaintenancePolicyMaxHealthPercentage: -1,
instanceMaintenancePolicyMinHealthPercentage: -1,
});

// Then
Expand All @@ -2446,7 +2446,7 @@ describe('InstanceMaintenancePolicy', () => {
});
});

test('throws if maintenancePolicyMaxHealthPercentage is greater than 200', () => {
test('throws if instanceMaintenancePolicyMaxHealthPercentage is greater than 200', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = mockVpc(stack);
Expand All @@ -2457,13 +2457,13 @@ describe('InstanceMaintenancePolicy', () => {
vpc,
instanceType: new ec2.InstanceType('t2.micro'),
machineImage: ec2.MachineImage.latestAmazonLinux2(),
maintenancePolicyMaxHealthPercentage: 250,
maintenancePolicyMinHealthPercentage: 100,
instanceMaintenancePolicyMaxHealthPercentage: 250,
instanceMaintenancePolicyMinHealthPercentage: 100,
});
}).toThrow(/maintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got 250/);
}).toThrow(/instanceMaintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got 250/);
});

test('throws if maintenancePolicyMaxHealthPercentage is less than 100', () => {
test('throws if instanceMaintenancePolicyMaxHealthPercentage is less than 100', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = mockVpc(stack);
Expand All @@ -2474,13 +2474,13 @@ describe('InstanceMaintenancePolicy', () => {
vpc,
instanceType: new ec2.InstanceType('t2.micro'),
machineImage: ec2.MachineImage.latestAmazonLinux2(),
maintenancePolicyMaxHealthPercentage: 50,
maintenancePolicyMinHealthPercentage: 100,
instanceMaintenancePolicyMaxHealthPercentage: 50,
instanceMaintenancePolicyMinHealthPercentage: 100,
});
}).toThrow(/maintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got 50/);
}).toThrow(/instanceMaintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got 50/);
});

test('throws if maintenancePolicyMinHealthPercentage is greater than 100', () => {
test('throws if instanceMaintenancePolicyMinHealthPercentage is greater than 100', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = mockVpc(stack);
Expand All @@ -2491,13 +2491,13 @@ describe('InstanceMaintenancePolicy', () => {
vpc,
instanceType: new ec2.InstanceType('t2.micro'),
machineImage: ec2.MachineImage.latestAmazonLinux2(),
maintenancePolicyMaxHealthPercentage: 200,
maintenancePolicyMinHealthPercentage: 150,
instanceMaintenancePolicyMaxHealthPercentage: 200,
instanceMaintenancePolicyMinHealthPercentage: 150,
});
}).toThrow(/maintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got 150/);
}).toThrow(/instanceMaintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got 150/);
});

test('throws if maintenancePolicyMinHealthPercentage is less than 0', () => {
test('throws if instanceMaintenancePolicyMinHealthPercentage is less than 0', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = mockVpc(stack);
Expand All @@ -2508,13 +2508,13 @@ describe('InstanceMaintenancePolicy', () => {
vpc,
instanceType: new ec2.InstanceType('t2.micro'),
machineImage: ec2.MachineImage.latestAmazonLinux2(),
maintenancePolicyMaxHealthPercentage: 200,
maintenancePolicyMinHealthPercentage: -100,
instanceMaintenancePolicyMaxHealthPercentage: 200,
instanceMaintenancePolicyMinHealthPercentage: -100,
});
}).toThrow(/maintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got -100/);
}).toThrow(/instanceMaintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got -100/);
});

test('throws if only maintenancePolicyMinHealthPercentage is set to -1', () => {
test('throws if only instanceMaintenancePolicyMinHealthPercentage is set to -1', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = mockVpc(stack);
Expand All @@ -2525,13 +2525,13 @@ describe('InstanceMaintenancePolicy', () => {
vpc,
instanceType: new ec2.InstanceType('t2.micro'),
machineImage: ec2.MachineImage.latestAmazonLinux2(),
maintenancePolicyMaxHealthPercentage: 200,
maintenancePolicyMinHealthPercentage: -1,
instanceMaintenancePolicyMaxHealthPercentage: 200,
instanceMaintenancePolicyMinHealthPercentage: -1,
});
}).toThrow(/Both maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got maintenancePolicyMinHealthPercentage: -1 and maintenancePolicyMaxHealthPercentage: 200/);
}).toThrow(/Both instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got instanceMaintenancePolicyMinHealthPercentage: -1 and instanceMaintenancePolicyMaxHealthPercentage: 200/);
});

test('throws if only maintenancePolicyMaxHealthPercentage is set to -1', () => {
test('throws if only instanceMaintenancePolicyMaxHealthPercentage is set to -1', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = mockVpc(stack);
Expand All @@ -2542,13 +2542,13 @@ describe('InstanceMaintenancePolicy', () => {
vpc,
instanceType: new ec2.InstanceType('t2.micro'),
machineImage: ec2.MachineImage.latestAmazonLinux2(),
maintenancePolicyMaxHealthPercentage: -1,
maintenancePolicyMinHealthPercentage: 100,
instanceMaintenancePolicyMaxHealthPercentage: -1,
instanceMaintenancePolicyMinHealthPercentage: 100,
});
}).toThrow(/Both maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got maintenancePolicyMinHealthPercentage: 100 and maintenancePolicyMaxHealthPercentage: -1/);
}).toThrow(/Both instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got instanceMaintenancePolicyMinHealthPercentage: 100 and instanceMaintenancePolicyMaxHealthPercentage: -1/);
});

test('throws if only maintenancePolicyMinHealthPercentage is specified', () => {
test('throws if only instanceMaintenancePolicyMinHealthPercentage is specified', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = mockVpc(stack);
Expand All @@ -2559,12 +2559,12 @@ describe('InstanceMaintenancePolicy', () => {
vpc,
instanceType: new ec2.InstanceType('t2.micro'),
machineImage: ec2.MachineImage.latestAmazonLinux2(),
maintenancePolicyMinHealthPercentage: 100,
instanceMaintenancePolicyMinHealthPercentage: 100,
});
}).toThrow(/Both or neither of maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be specified, got maintenancePolicyMinHealthPercentage: 100 and maintenancePolicyMaxHealthPercentage: undefined/);
}).toThrow(/Both or neither of instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage must be specified, got instanceMaintenancePolicyMinHealthPercentage: 100 and instanceMaintenancePolicyMaxHealthPercentage: undefined/);
});

test('throws if only maintenancePolicyMaxHealthPercentage is specified', () => {
test('throws if only instanceMaintenancePolicyMaxHealthPercentage is specified', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = mockVpc(stack);
Expand All @@ -2575,12 +2575,12 @@ describe('InstanceMaintenancePolicy', () => {
vpc,
instanceType: new ec2.InstanceType('t2.micro'),
machineImage: ec2.MachineImage.latestAmazonLinux2(),
maintenancePolicyMaxHealthPercentage: 200,
instanceMaintenancePolicyMaxHealthPercentage: 200,
});
}).toThrow(/Both or neither of maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be specified, got maintenancePolicyMinHealthPercentage: undefined and maintenancePolicyMaxHealthPercentage: 200/);
}).toThrow(/Both or neither of instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage must be specified, got instanceMaintenancePolicyMinHealthPercentage: undefined and instanceMaintenancePolicyMaxHealthPercentage: 200/);
});

test('throws if a difference between maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage is greater than 100', () => {
test('throws if a difference between instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage is greater than 100', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = mockVpc(stack);
Expand All @@ -2591,10 +2591,10 @@ describe('InstanceMaintenancePolicy', () => {
vpc,
instanceType: new ec2.InstanceType('t2.micro'),
machineImage: ec2.MachineImage.latestAmazonLinux2(),
maintenancePolicyMaxHealthPercentage: 200,
maintenancePolicyMinHealthPercentage: 0,
instanceMaintenancePolicyMaxHealthPercentage: 200,
instanceMaintenancePolicyMinHealthPercentage: 0,
});
}).toThrow(/The difference between maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage cannot be greater than 100, got 200/);
}).toThrow(/The difference between instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage cannot be greater than 100, got 200/);
});
});

Expand Down

0 comments on commit 5eb173e

Please sign in to comment.