Skip to content

Commit

Permalink
fix(cloudwatch): move SNS Alarm Action to aws-cloudwatch-actions (#…
Browse files Browse the repository at this point in the history
…2688)

In accordance with new guidelines, we're centralizing cross-service
integrations into their own package. In this case, centralizing
CloudWatch Alarm Actions into `@aws-cdk/aws-cloudwatch-actions`.

Not moving AutoScaling classes because doing so would introduce circular
dependencies.

BREAKING CHANGE: using an SNS topic as CloudWatch Alarm Actxion now
requires an integration object from the `@aws-cdk/aws-cloudwatch-actions`
package.
  • Loading branch information
rix0rrr authored Jun 5, 2019
1 parent 56e9155 commit e3df21a
Show file tree
Hide file tree
Showing 105 changed files with 13,462 additions and 14,447 deletions.
11 changes: 3 additions & 8 deletions packages/@aws-cdk/app-delivery/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions packages/@aws-cdk/assert/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 6 additions & 16 deletions packages/@aws-cdk/assets-docker/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 14 additions & 36 deletions packages/@aws-cdk/assets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import cloudwatch = require('@aws-cdk/aws-cloudwatch');
import cdk = require('@aws-cdk/cdk');
import { CfnScalingPolicy } from './applicationautoscaling.generated';
import { IScalableTarget } from './scalable-target';
Expand Down Expand Up @@ -67,17 +66,12 @@ export interface StepScalingActionProps {
*
* This Action must be used as the target of a CloudWatch alarm to take effect.
*/
export class StepScalingAction extends cdk.Construct implements cloudwatch.IAlarmAction {
export class StepScalingAction extends cdk.Construct {
/**
* ARN of the scaling policy
*/
public readonly scalingPolicyArn: string;

/**
* ARN when this scaling policy is used as an Alarm action
*/
public readonly alarmActionArn: string;

private readonly adjustments = new Array<CfnScalingPolicy.StepAdjustmentProperty>();

constructor(scope: cdk.Construct, id: string, props: StepScalingActionProps) {
Expand All @@ -100,7 +94,6 @@ export class StepScalingAction extends cdk.Construct implements cloudwatch.IAlar
});

this.scalingPolicyArn = resource.scalingPolicyArn;
this.alarmActionArn = this.scalingPolicyArn;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class StepScalingPolicy extends cdk.Construct {
evaluationPeriods: 1,
threshold,
});
this.lowerAlarm.addAlarmAction(this.lowerAction);
this.lowerAlarm.addAlarmAction(new StepScalingAlarmAction(this.lowerAction));
}

if (alarms.upperAlarmIntervalIndex !== undefined) {
Expand Down Expand Up @@ -138,7 +138,7 @@ export class StepScalingPolicy extends cdk.Construct {
evaluationPeriods: 1,
threshold,
});
this.upperAlarm.addAlarmAction(this.upperAction);
this.upperAlarm.addAlarmAction(new StepScalingAlarmAction(this.upperAction));
}
}
}
Expand Down Expand Up @@ -191,4 +191,22 @@ function aggregationTypeFromMetric(metric: cloudwatch.Metric): MetricAggregation
default:
throw new Error(`Cannot only scale on 'Minimum', 'Maximum', 'Average' metrics, got ${metric.statistic}`);
}
}
}

/**
* Use a StepScalingAction as an Alarm Action
*
* This class is here and not in aws-cloudwatch-actions because this library
* needs to use the class, and otherwise we'd have a circular dependency:
*
* aws-autoscaling -> aws-cloudwatch-actions (for using the Action)
* aws-cloudwatch-actions -> aws-autoscaling (for the definition of IStepScalingAction)
*/
class StepScalingAlarmAction implements cloudwatch.IAlarmAction {
constructor(private readonly stepScalingAction: StepScalingAction) {
}

public bind(_scope: cdk.Construct, _alarm: cloudwatch.IAlarm): cloudwatch.AlarmActionConfig {
return { alarmActionArn: this.stepScalingAction.scalingPolicyArn };
}
}
Loading

0 comments on commit e3df21a

Please sign in to comment.