diff --git a/src/index.js b/src/index.js index 28d077a..f46986e 100644 --- a/src/index.js +++ b/src/index.js @@ -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) { diff --git a/src/index.test.js b/src/index.test.js index 62b7c3d..d2c2748 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -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({