Skip to content

Commit

Permalink
contentBasedDeduplication only on fifo topics
Browse files Browse the repository at this point in the history
  • Loading branch information
msambol committed Apr 5, 2024
1 parent c466407 commit 1c533f0
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 23 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,59 @@
"SignatureVersion": "2",
"TopicName": "fooTopicSignatureVersion"
}
},
"MyTopic288CE2107": {
"Type": "AWS::SNS::Topic",
"Properties": {
"DisplayName": "fooDisplayName2",
"KmsMasterKeyId": {
"Fn::GetAtt": [
"CustomKey1E6D0D07",
"Arn"
]
},
"TopicName": "fooTopic2"
}
},
"PublishRoleF42F66B6": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "s3.amazonaws.com"
}
}
],
"Version": "2012-10-17"
}
}
},
"PublishRoleDefaultPolicy9257B12D": {
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyDocument": {
"Statement": [
{
"Action": "sns:Publish",
"Effect": "Allow",
"Resource": {
"Ref": "MyTopic288CE2107"
}
}
],
"Version": "2012-10-17"
},
"PolicyName": "PublishRoleDefaultPolicy9257B12D",
"Roles": [
{
"Ref": "PublishRoleF42F66B6"
}
]
}
}
},
"Parameters": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions packages/aws-cdk-lib/aws-sns/lib/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,17 @@ export class Topic extends TopicBase {
* @param attrs the attributes of the topic to import
*/
public static fromTopicAttributes(scope: Construct, id: string, attrs: TopicAttributes): ITopic {
const topicName = Stack.of(scope).splitArn(attrs.topicArn, ArnFormat.NO_RESOURCE_NAME).resource;
const fifo = topicName.endsWith('.fifo');

if (attrs.contentBasedDeduplication && !fifo) {
throw new Error('Cannot import topic; contentBasedDeduplication is only available for FIFO SNS topics.');
}

class Import extends TopicBase {
public readonly topicArn = attrs.topicArn;
public readonly topicName = Stack.of(scope).splitArn(attrs.topicArn, ArnFormat.NO_RESOURCE_NAME).resource;
public readonly fifo = this.topicName.endsWith('.fifo');
public readonly topicName = topicName;
public readonly fifo = fifo;
public readonly contentBasedDeduplication = attrs.contentBasedDeduplication || false;
protected autoCreatePolicy: boolean = false;
}
Expand Down
11 changes: 11 additions & 0 deletions packages/aws-cdk-lib/aws-sns/test/sns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,17 @@ describe('Topic', () => {
expect(imported.contentBasedDeduplication).toEqual(true);
});

test('fromTopicAttributes throws with contentBasedDeduplication on non-fifo topic', () => {
// GIVEN
const stack = new cdk.Stack();

// WHEN
expect(() => sns.Topic.fromTopicAttributes(stack, 'Imported', {
topicArn: 'arn:aws:sns:*:123456789012:mytopic',
contentBasedDeduplication: true,
})).toThrow(/Cannot import topic; contentBasedDeduplication is only available for FIFO SNS topics./);
});

test('sets account for imported topic env', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down

0 comments on commit 1c533f0

Please sign in to comment.