Skip to content

Commit

Permalink
feat(autoscaling): add instanceMonitoring option
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.

fixes #8212
  • Loading branch information
rbobrowicz committed May 26, 2020
1 parent b4adf07 commit 7d7537e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/@aws-cdk/aws-autoscaling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ To enable the max instance lifetime support, specify `maxInstanceLifetime` prope
for the `AutoscalingGroup` resource. The value must be between 7 and 365 days(inclusive).
To clear a previously set value, just leave this property undefinied.

### Instance Monitoring

To disable detailed instance monitoring, specify `instanceMonitoring` property
for the `AutoscalingGroup` resource as `false`. Otherwise detailed monitoring
will be enabled.


### Future work
Expand Down
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 7d7537e

Please sign in to comment.