Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #124 from justinjmoses/master
Browse files Browse the repository at this point in the history
When topics give to custom alarms, they are connected to the custom alarm, not replaced
  • Loading branch information
adikari authored Jun 9, 2020
2 parents 95eae15 + b23ecee commit b777da6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,12 @@ class AlertsPlugin {

if (topic) {
if (isTopicConfigAnImport || topic.indexOf('arn:') === 0) {
alertTopics[key] = topic;
if (customAlarmName) {
alertTopics[customAlarmName] = alertTopics[customAlarmName] || {};
alertTopics[customAlarmName][key] = topic;
} else {
alertTopics[key] = topic;
}
} else {
const cfRef = `AwsAlerts${customAlarmName ? _.upperFirst(customAlarmName) : ''}${_.upperFirst(key)}`;
if (customAlarmName) {
Expand Down
32 changes: 32 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,38 @@ describe('#index', function () {
expect(plugin.serverless.service.provider.compiledCloudFormationTemplate.Resources).toEqual({});
});

it('should not create SNS topic when ARN is passed to custom topic', () => {
const topicName = 'arn:aws:sns:us-east-1:123456789012:ok-topic';

const plugin = pluginFactory({
topics: {
customAlert: {
alarm: {
topic: topicName,
},
ok: {
topic: topicName,
},
},
},
});

const config = plugin.getConfig();
const topics = plugin.compileAlertTopics(config);

expect(topics).toEqual({
customAlert: {
alarm: topicName,
ok: topicName,
},
});

expect(
plugin.serverless.service.provider.compiledCloudFormationTemplate
.Resources
).toEqual({});
});

it('should create SNS topic when name is passed', () => {
const topicName = 'ok-topic';
const plugin = pluginFactory({
Expand Down

0 comments on commit b777da6

Please sign in to comment.