Skip to content

Commit

Permalink
feat(sns): fifo topic with content-based deduplication support aws#11127
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Rhodes committed Nov 19, 2020
1 parent 9b72fc8 commit d74a3a8
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/@aws-cdk/aws-sns/lib/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ export interface TopicProps {
* @default None
*/
readonly masterKey?: IKey;

/**
* Enables content-based deduplication for FIFO topics.
*
* @default None
*/
readonly contentBasedDeduplication?: boolean;

/**
* Set to true to create a FIFO topic.
*
* @default None
*/
readonly fifoTopic?: boolean;
}

/**
Expand Down Expand Up @@ -70,6 +84,8 @@ export class Topic extends TopicBase {
displayName: props.displayName,
topicName: this.physicalName,
kmsMasterKeyId: props.masterKey && props.masterKey.keyArn,
contentBasedDeduplication: props.contentBasedDeduplication,
fifoTopic: props.fifoTopic,
});

this.topicArn = this.getResourceArnAttribute(resource.ref, {
Expand Down
13 changes: 13 additions & 0 deletions packages/@aws-cdk/aws-sns/test/integ.sns-fifo.expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Resources": {
"MyTopic86869434": {
"Type": "AWS::SNS::Topic",
"Properties": {
"ContentBasedDeduplication": true,
"DisplayName": "fooDisplayName",
"FifoTopic": true,
"TopicName": "fooTopic.fifo"
}
}
}
}
21 changes: 21 additions & 0 deletions packages/@aws-cdk/aws-sns/test/integ.sns-fifo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { App, Stack, StackProps } from '@aws-cdk/core';
import { Topic } from '../lib';

class SNSFifoInteg extends Stack {
constructor(scope: App, id: string, props?: StackProps) {
super(scope, id, props);

new Topic(this, 'MyTopic', {
topicName: 'fooTopic.fifo',
displayName: 'fooDisplayName',
contentBasedDeduplication: true,
fifoTopic: true,
});
}
}

const app = new App();

new SNSFifoInteg(app, 'SNSFifoInteg');

app.synth();
42 changes: 42 additions & 0 deletions packages/@aws-cdk/aws-sns/test/test.sns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,48 @@ export = {

test.done();
},

'specify contentBasedDeduplication'(test: Test) {
const stack = new cdk.Stack();

new sns.Topic(stack, 'MyTopic', {
contentBasedDeduplication: true,
});

expect(stack).toMatch({
'Resources': {
'MyTopic86869434': {
'Type': 'AWS::SNS::Topic',
'Properties': {
'ContentBasedDeduplication': true,
},
},
},
});

test.done();
},

'specify fifoTopic'(test: Test) {
const stack = new cdk.Stack();

new sns.Topic(stack, 'MyTopic', {
fifoTopic: true,
});

expect(stack).toMatch({
'Resources': {
'MyTopic86869434': {
'Type': 'AWS::SNS::Topic',
'Properties': {
'FifoTopic': true,
},
},
},
});

test.done();
},
},

'can add a policy to the topic'(test: Test) {
Expand Down

0 comments on commit d74a3a8

Please sign in to comment.