Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(aws-cloudwatch-actions): Add the possibility to have SSM Incident Action #20553

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/@aws-cdk/aws-cloudwatch-actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,16 @@ alarm.addAlarmAction(
);
```

## SSM Incident Manager Action Example

```ts
declare const alarm: cloudwatch.Alarm;
// Create an Incident Manager incident based on a specific response plan
alarm.addAlarmAction(
new actions.SsmIncidentAction(
'arn:aws:ssm-incidents::123456789012:response-plan/ResponsePlanName'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'arn:aws:ssm-incidents::123456789012:response-plan/ResponsePlanName'
'arn:aws:ssm-incidents::123456789012:response-plan/ResponsePlanName',

)
);
```

See `@aws-cdk/aws-cloudwatch` for more information.
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-cloudwatch-actions/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './autoscaling';
export * from './sns';
export * from './ec2';
export * from './ssm';
export * from './ssm-incidents';
Copy link
Contributor

@comcalvi comcalvi Jun 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export * from './ssm-incidents';
export * from './ssm-incidents';

20 changes: 20 additions & 0 deletions packages/@aws-cdk/aws-cloudwatch-actions/lib/ssm-incidents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
Copy link
Contributor

@comcalvi comcalvi Jun 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic should be moved into ssm.ts.

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) {
}
Comment on lines +8 to +9
Copy link
Contributor

@comcalvi comcalvi Jun 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
constructor(private readonly responsePlanArn: string) {
}
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,
};
}
}
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],
});
});