-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(aws-cloudwatch-actions): Add the possibility to have SSM Incident Ac…
…tion 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)
- Loading branch information
1 parent
d814293
commit a85da25
Showing
4 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/@aws-cdk/aws-cloudwatch-actions/lib/ssm-incidents.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; | ||
import { Construct } from '@aws-cdk/core'; | ||
|
||
/** | ||
* Use an SSM Incident as an alarm action | ||
*/ | ||
export class SsmIncidentAction implements cloudwatch.IAlarmAction { | ||
constructor(private readonly responsePlanArn: string) { | ||
} | ||
|
||
/** | ||
* Returns an alarm action configuration to use an SSM Incident as an alarm action | ||
* based on an Incident Manager Response Plan | ||
*/ | ||
bind(_scope: Construct, _alarm: cloudwatch.IAlarm): cloudwatch.AlarmActionConfig { | ||
return { | ||
alarmActionArn: this.responsePlanArn, | ||
}; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/@aws-cdk/aws-cloudwatch-actions/test/ssm-incidents.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Template } from '@aws-cdk/assertions'; | ||
import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; | ||
import { Stack } from '@aws-cdk/core'; | ||
import * as actions from '../lib'; | ||
|
||
test('can use SSM Incident as alarm action', () => { | ||
// GIVEN | ||
const stack = new Stack(); | ||
const alarm = new cloudwatch.Alarm(stack, 'Alarm', { | ||
metric: new cloudwatch.Metric({ namespace: 'AWS', metricName: 'Test' }), | ||
evaluationPeriods: 3, | ||
threshold: 100, | ||
}); | ||
|
||
// WHEN | ||
const responsePlanArn = 'arn:aws:ssm-incidents::123456789012:response-plan/ResponsePlanName'; | ||
alarm.addAlarmAction(new actions.SsmIncidentAction(responsePlanArn)); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::CloudWatch::Alarm', { | ||
AlarmActions: [responsePlanArn], | ||
}); | ||
}); |