File tree Expand file tree Collapse file tree
packages/@aws-cdk/aws-cloudwatch-actions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,4 +38,16 @@ alarm.addAlarmAction(
3838);
3939```
4040
41+ ## SSM Incident Manager Action Example
42+
43+ ``` ts
44+ declare const alarm: cloudwatch .Alarm ;
45+ // Create an Incident Manager incident based on a specific response plan
46+ alarm .addAlarmAction (
47+ new actions .SsmIncidentAction (
48+ ' arn:aws:ssm-incidents::123456789012:response-plan/ResponsePlanName'
49+ )
50+ );
51+ ```
52+
4153See ` @aws-cdk/aws-cloudwatch ` for more information.
Original file line number Diff line number Diff line change @@ -3,3 +3,4 @@ export * from './autoscaling';
33export * from './sns' ;
44export * from './ec2' ;
55export * from './ssm' ;
6+ export * from './ssm-incidents' ;
Original file line number Diff line number Diff line change 1+ import * as cloudwatch from '@aws-cdk/aws-cloudwatch' ;
2+ import { Construct } from '@aws-cdk/core' ;
3+
4+ /**
5+ * Use an SSM Incident as an alarm action
6+ */
7+ export class SsmIncidentAction implements cloudwatch . IAlarmAction {
8+ constructor ( private readonly responsePlanArn : string ) {
9+ }
10+
11+ /**
12+ * Returns an alarm action configuration to use an SSM Incident as an alarm action
13+ * based on an Incident Manager Response Plan
14+ */
15+ bind ( _scope : Construct , _alarm : cloudwatch . IAlarm ) : cloudwatch . AlarmActionConfig {
16+ return {
17+ alarmActionArn : this . responsePlanArn ,
18+ } ;
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ import { Template } from '@aws-cdk/assertions' ;
2+ import * as cloudwatch from '@aws-cdk/aws-cloudwatch' ;
3+ import { Stack } from '@aws-cdk/core' ;
4+ import * as actions from '../lib' ;
5+
6+ test ( 'can use SSM Incident as alarm action' , ( ) => {
7+ // GIVEN
8+ const stack = new Stack ( ) ;
9+ const alarm = new cloudwatch . Alarm ( stack , 'Alarm' , {
10+ metric : new cloudwatch . Metric ( { namespace : 'AWS' , metricName : 'Test' } ) ,
11+ evaluationPeriods : 3 ,
12+ threshold : 100 ,
13+ } ) ;
14+
15+ // WHEN
16+ const responsePlanArn = 'arn:aws:ssm-incidents::123456789012:response-plan/ResponsePlanName' ;
17+ alarm . addAlarmAction ( new actions . SsmIncidentAction ( responsePlanArn ) ) ;
18+
19+ // THEN
20+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::CloudWatch::Alarm' , {
21+ AlarmActions : [ responsePlanArn ] ,
22+ } ) ;
23+ } ) ;
You can’t perform that action at this time.
0 commit comments