Skip to content

Commit

Permalink
fix(AWS SNS): Recognize displayName as optional (#8323)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericbarthelet committed Oct 1, 2020
1 parent 73c34b9 commit a020a4a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/plugins/aws/package/compile/events/sns/index.js
Expand Up @@ -45,7 +45,7 @@ class AwsCompileSNSEvents {
additionalProperties: false,
},
},
oneOf: [{ required: ['arn'] }, { required: ['topicName', 'displayName'] }],
oneOf: [{ required: ['arn'] }, { required: ['topicName'] }],
additionalProperties: false,
},
],
Expand All @@ -64,7 +64,6 @@ class AwsCompileSNSEvents {
let topicArn;
let topicName;
let region;
let displayName = '';
let redrivePolicy;
if (typeof event.sns === 'object') {
if (event.sns.arn) {
Expand All @@ -91,7 +90,6 @@ class AwsCompileSNSEvents {
);
}
} else {
displayName = event.sns.displayName;
topicName = event.sns.topicName;
}
} else if (event.sns.indexOf('arn:') === 0) {
Expand Down Expand Up @@ -229,13 +227,14 @@ class AwsCompileSNSEvents {
};

if (!(topicLogicalId in template.Resources)) {
const topicResourceProperties = { TopicName: topicName };
if (event.sns.displayName) {
topicResourceProperties.DisplayName = event.sns.displayName;
}
_.merge(template.Resources, {
[topicLogicalId]: {
Type: 'AWS::SNS::Topic',
Properties: {
TopicName: topicName,
DisplayName: displayName,
},
Properties: topicResourceProperties,
},
});
}
Expand Down
21 changes: 21 additions & 0 deletions lib/plugins/aws/package/compile/events/sns/index.test.js
Expand Up @@ -87,6 +87,27 @@ describe('AwsCompileSNSEvents', () => {
).to.eql({ pet: ['dog', 'cat'] });
});

it('should allow SNS topic without displayName', () => {
awsCompileSNSEvents.serverless.service.functions = {
first: {
events: [
{
sns: {
topicName: 'Topic 1',
},
},
],
},
};

awsCompileSNSEvents.compileSNSEvents();

expect(
awsCompileSNSEvents.serverless.service.provider.compiledCloudFormationTemplate.Resources
.SNSTopicTopic1.Properties
).to.to.not.have.property('DisplayName');
});

it('should create corresponding resources when topic is defined in resources', () => {
awsCompileSNSEvents.serverless.service.functions = {
first: {
Expand Down

0 comments on commit a020a4a

Please sign in to comment.