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

SNS displayName as optional property when used with topicName #8323

Merged
merged 2 commits into from Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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