Skip to content

Commit

Permalink
feat(autoscaling): add instanceMonitoring option (#8212)
Browse files Browse the repository at this point in the history
Gives users the option to choose between detailed and basic monitoring.
Defaults to detailed when not specified, maintaining current behavior.
  • Loading branch information
rbobrowicz committed May 26, 2020
1 parent c2e9c77 commit da9baf7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ export interface CommonAutoScalingGroupProps {
* @default none
*/
readonly maxInstanceLifetime?: Duration;

/**
* Controls whether instances in this group are launched with detailed (true) or basic (false) monitoring.
*
* When detailed monitoring is enabled, Amazon CloudWatch generates metrics every minute and your account
* is charged a fee. When you disable detailed monitoring, CloudWatch generates metrics every 5 minutes.
*
* @see https://docs.aws.amazon.com/autoscaling/latest/userguide/as-instance-monitoring.html#enable-as-instance-metrics
*
* @default true
*/
readonly instanceMonitoring?: boolean;
}

/**
Expand Down Expand Up @@ -468,6 +480,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements
imageId: imageConfig.imageId,
keyName: props.keyName,
instanceType: props.instanceType.toString(),
instanceMonitoring: props.instanceMonitoring,
securityGroups: securityGroupsToken,
iamInstanceProfile: iamProfile.ref,
userData: userDataToken,
Expand Down
20 changes: 20 additions & 0 deletions packages/@aws-cdk/aws-autoscaling/test/test.auto-scaling-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,26 @@ export = {
test.done();
},

'can configure instance monitoring'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = mockVpc(stack);

// WHEN
new autoscaling.AutoScalingGroup(stack, 'MyStack', {
instanceType: ec2.InstanceType.of(ec2.InstanceClass.M4, ec2.InstanceSize.MICRO),
machineImage: new ec2.AmazonLinuxImage(),
vpc,
instanceMonitoring: false,
});

// THEN
expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', {
InstanceMonitoring: false,
}));
test.done();
},

'throws if ephemeral volumeIndex < 0'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down

0 comments on commit da9baf7

Please sign in to comment.