-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(actions): add feature to add multiple actions to an alarm (#29)
Users will be able to use `multipleActions(action1, action2, etc)` to add multiple actions to a single alarm.
- Loading branch information
Showing
5 changed files
with
140 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { | ||
AlarmActionStrategyProps, | ||
IAlarmActionStrategy, | ||
} from "./IAlarmActionStrategy"; | ||
|
||
export function multipleActions(...actions: IAlarmActionStrategy[]) { | ||
return new MultipleAlarmActionStrategy(actions); | ||
} | ||
|
||
/** | ||
* Alarm action strategy that combines multiple actions in the same order as they were given. | ||
*/ | ||
export class MultipleAlarmActionStrategy implements IAlarmActionStrategy { | ||
protected readonly actions: IAlarmActionStrategy[]; | ||
|
||
constructor(actions: IAlarmActionStrategy[]) { | ||
this.actions = actions; | ||
} | ||
|
||
addAlarmActions(props: AlarmActionStrategyProps): void { | ||
this.actions.forEach((action) => action.addAlarmActions(props)); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { SynthUtils } from "@monocdk-experiment/assert"; | ||
import { Stack } from "monocdk"; | ||
import { Alarm, Metric } from "monocdk/aws-cloudwatch"; | ||
import { Topic } from "monocdk/aws-sns"; | ||
|
||
import { multipleActions, SnsAlarmActionStrategy } from "../../../lib"; | ||
|
||
test("snapshot test: multiple actions", () => { | ||
const stack = new Stack(); | ||
const topic1 = new Topic(stack, "DummyTopic1"); | ||
const topic2 = new Topic(stack, "DummyTopic2"); | ||
const topic3 = new Topic(stack, "DummyTopic3"); | ||
const alarm = new Alarm(stack, "DummyAlarm", { | ||
evaluationPeriods: 1, | ||
threshold: 0, | ||
metric: new Metric({ namespace: "Dummy", metricName: "Dummy" }), | ||
}); | ||
const action = multipleActions( | ||
new SnsAlarmActionStrategy({ onAlarmTopic: topic1 }), | ||
new SnsAlarmActionStrategy({ onAlarmTopic: topic2 }), | ||
new SnsAlarmActionStrategy({ onAlarmTopic: topic3 }) | ||
); | ||
action.addAlarmActions({ alarm, action }); | ||
|
||
expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot(); | ||
}); |
40 changes: 40 additions & 0 deletions
40
test/common/alarm/__snapshots__/MultipleAlarmActionStrategy.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.