Skip to content

Commit a85da25

Browse files
committed
(aws-cloudwatch-actions): Add the possibility to have SSM Incident Action
This small PR will add SSM Incident action to cloudwatch alarm. The arn format was taken from the UI console (under Incident Manager Response Plan)
1 parent d814293 commit a85da25

4 files changed

Lines changed: 56 additions & 0 deletions

File tree

packages/@aws-cdk/aws-cloudwatch-actions/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
4153
See `@aws-cdk/aws-cloudwatch` for more information.

packages/@aws-cdk/aws-cloudwatch-actions/lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './autoscaling';
33
export * from './sns';
44
export * from './ec2';
55
export * from './ssm';
6+
export * from './ssm-incidents';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
});

0 commit comments

Comments
 (0)