From 184c68ef5226384234ecbad9dc139995b4627bad Mon Sep 17 00:00:00 2001 From: maz Date: Wed, 22 Jan 2025 21:10:47 +0900 Subject: [PATCH 1/5] feat(sns): support high throughput mode for FIFO topics --- .../test/integ.sns-fifo-throughput-scope.ts | 28 ++++++++++++++++++ packages/aws-cdk-lib/aws-sns/README.md | 20 +++++++++++++ packages/aws-cdk-lib/aws-sns/lib/topic.ts | 29 +++++++++++++++++++ packages/aws-cdk-lib/aws-sns/test/sns.test.ts | 20 +++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.ts diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.ts new file mode 100644 index 0000000000000..7c41b9ee6c927 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.ts @@ -0,0 +1,28 @@ +import { App, Stack, StackProps} from 'aws-cdk-lib'; +import { FifoThroughputScope, Topic } from 'aws-cdk-lib/aws-sns'; + +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; + +class SNSInteg extends Stack { + constructor(scope: App, id: string, props?: StackProps) { + super(scope, id, props); + + new Topic(this, 'MessageGroupScopeTopic', { + fifo: true, + fifoThroughputScope: FifoThroughputScope.MESSAGE_GROUP, + }); + + new Topic(this, 'TopicScopeTopic', { + fifo: true, + fifoThroughputScope: FifoThroughputScope.TOPIC, + }); + } +} + +const app = new App(); + +const stack = new SNSInteg(app, 'sns-fifo-throughput-scope'); + +new IntegTest(app, 'sns-fifo-throughput-scope-test', { + testCases: [stack], +}); diff --git a/packages/aws-cdk-lib/aws-sns/README.md b/packages/aws-cdk-lib/aws-sns/README.md index b4b219319b536..57534a253119a 100644 --- a/packages/aws-cdk-lib/aws-sns/README.md +++ b/packages/aws-cdk-lib/aws-sns/README.md @@ -344,3 +344,23 @@ const topic = new sns.Topic(this, 'MyTopic', { tracingConfig: sns.TracingConfig.ACTIVE, }); ``` + +## High-throughput mode for Amazon SNS FIFO Topics + +High throughput FIFO topics in Amazon SNS efficiently manage high message throughput while maintaining strict message order, ensuring reliability and scalability for applications processing numerous messages. +This solution is ideal for scenarios demanding both high throughput and ordered message delivery. + +To improve message throughput using high throughput FIFO topics, increasing the number of message groups is recommended. + +For more information, see [High throughput FIFO topics in Amazon SNS](https://docs.aws.amazon.com/sns/latest/dg/fifo-high-throughput.html). + +You can configure high-throughput mode for your FIFO topics by setting `fifoThroughputScope` property. + +```ts +const topic = new sns.Topic(this, 'MyTopic', { + fifo: true, + fifoThroughputScope: sns.FifoThroughputScope.TOPIC, +}); +``` + +**Note**: The `fifoThroughputScope` property is only available for FIFO topics. diff --git a/packages/aws-cdk-lib/aws-sns/lib/topic.ts b/packages/aws-cdk-lib/aws-sns/lib/topic.ts index f78b32bf8cfe3..a3b5166c84d7e 100644 --- a/packages/aws-cdk-lib/aws-sns/lib/topic.ts +++ b/packages/aws-cdk-lib/aws-sns/lib/topic.ts @@ -98,6 +98,34 @@ export interface TopicProps { * @default TracingConfig.PASS_THROUGH */ readonly tracingConfig?: TracingConfig; + + /** + * Specifies the throughput quota and deduplication behavior to apply for the FIFO topic. + * + * You can only set this propery when `fifo` is `true`. + * + * @default - None. SNS default setting is FifoThroughputScope.TOPIC + */ + readonly fifoThroughputScope?: FifoThroughputScope; +} + +/** + * The throughput quota and deduplication behavior to apply for the FIFO topic. + */ +export enum FifoThroughputScope { + /** + * Topic scope + * - Throughput: 3000 message per second and a bandwidth of 20MB per second. + * - Deduplication: Message deduplication is verified on the entire FIFO topic. + */ + TOPIC = 'Topic', + + /** + * Message group scope + * - Throughput: Maximum regional limits. + * - Deduplication: Message deduplication is only verified within a message group. + */ + MESSAGE_GROUP = 'MessageGroup', } /** @@ -315,6 +343,7 @@ export class Topic extends TopicBase { signatureVersion: props.signatureVersion, deliveryStatusLogging: Lazy.any({ produce: () => this.renderLoggingConfigs() }, { omitEmptyArray: true }), tracingConfig: props.tracingConfig, + fifoThroughputScope: props.fifoThroughputScope, }); this.topicArn = this.getResourceArnAttribute(resource.ref, { diff --git a/packages/aws-cdk-lib/aws-sns/test/sns.test.ts b/packages/aws-cdk-lib/aws-sns/test/sns.test.ts index 6c8f04fb096b6..2476e9ce31428 100644 --- a/packages/aws-cdk-lib/aws-sns/test/sns.test.ts +++ b/packages/aws-cdk-lib/aws-sns/test/sns.test.ts @@ -854,4 +854,24 @@ describe('Topic', () => { }); }); }); + + describe('fifoThroughputScope', () => { + test.each([sns.FifoThroughputScope.MESSAGE_GROUP, sns.FifoThroughputScope.TOPIC])('set fifoThroughputScope to %s', (fifoThroughputScope) => { + // GIVEN + const app = new cdk.App(); + const stack = new cdk.Stack(app); + + // WHEN + new sns.Topic(stack, 'MyTopic', { + fifo: true, + fifoThroughputScope, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::SNS::Topic', { + FifoTopic: true, + FifoThroughputScope: fifoThroughputScope, + }); + }); + }); }); From d79d4c857bdbecbf863cb1d1153908777d9100eb Mon Sep 17 00:00:00 2001 From: maz Date: Wed, 22 Jan 2025 22:41:00 +0900 Subject: [PATCH 2/5] integ --- .../cdk.out | 1 + .../integ.json | 12 ++ .../manifest.json | 119 ++++++++++++++ .../sns-fifo-throughput-scope.assets.json | 19 +++ .../sns-fifo-throughput-scope.template.json | 54 +++++++ ...efaultTestDeployAssertBAF90E92.assets.json | 19 +++ ...aultTestDeployAssertBAF90E92.template.json | 36 +++++ .../tree.json | 153 ++++++++++++++++++ .../test/integ.sns-fifo-throughput-scope.ts | 2 +- packages/aws-cdk-lib/aws-sns/README.md | 2 +- packages/aws-cdk-lib/aws-sns/lib/topic.ts | 4 +- 11 files changed, 417 insertions(+), 4 deletions(-) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/integ.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/sns-fifo-throughput-scope.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/sns-fifo-throughput-scope.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/snsfifothroughputscopetestDefaultTestDeployAssertBAF90E92.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/snsfifothroughputscopetestDefaultTestDeployAssertBAF90E92.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/tree.json diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/cdk.out new file mode 100644 index 0000000000000..91e1a8b9901d5 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"39.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/integ.json new file mode 100644 index 0000000000000..9a7b76d148fb2 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "39.0.0", + "testCases": { + "sns-fifo-throughput-scope-test/DefaultTest": { + "stacks": [ + "sns-fifo-throughput-scope" + ], + "assertionStack": "sns-fifo-throughput-scope-test/DefaultTest/DeployAssert", + "assertionStackName": "snsfifothroughputscopetestDefaultTestDeployAssertBAF90E92" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/manifest.json new file mode 100644 index 0000000000000..62f53ca3df8f3 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/manifest.json @@ -0,0 +1,119 @@ +{ + "version": "39.0.0", + "artifacts": { + "sns-fifo-throughput-scope.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "sns-fifo-throughput-scope.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "sns-fifo-throughput-scope": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "sns-fifo-throughput-scope.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/f479d71edc397ab84e3385982c1e1598b5b59f17c8258c137fb2b424bb1d489d.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "sns-fifo-throughput-scope.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "sns-fifo-throughput-scope.assets" + ], + "metadata": { + "/sns-fifo-throughput-scope/MessageGroupScopeTopic/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MessageGroupScopeTopicAB4E2D6F" + } + ], + "/sns-fifo-throughput-scope/TopicScopeTopic/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "TopicScopeTopic8DEBB616" + } + ], + "/sns-fifo-throughput-scope/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/sns-fifo-throughput-scope/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "sns-fifo-throughput-scope" + }, + "snsfifothroughputscopetestDefaultTestDeployAssertBAF90E92.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "snsfifothroughputscopetestDefaultTestDeployAssertBAF90E92.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "snsfifothroughputscopetestDefaultTestDeployAssertBAF90E92": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "snsfifothroughputscopetestDefaultTestDeployAssertBAF90E92.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "snsfifothroughputscopetestDefaultTestDeployAssertBAF90E92.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "snsfifothroughputscopetestDefaultTestDeployAssertBAF90E92.assets" + ], + "metadata": { + "/sns-fifo-throughput-scope-test/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/sns-fifo-throughput-scope-test/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "sns-fifo-throughput-scope-test/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/sns-fifo-throughput-scope.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/sns-fifo-throughput-scope.assets.json new file mode 100644 index 0000000000000..8c5792538e5db --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/sns-fifo-throughput-scope.assets.json @@ -0,0 +1,19 @@ +{ + "version": "39.0.0", + "files": { + "f479d71edc397ab84e3385982c1e1598b5b59f17c8258c137fb2b424bb1d489d": { + "source": { + "path": "sns-fifo-throughput-scope.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "f479d71edc397ab84e3385982c1e1598b5b59f17c8258c137fb2b424bb1d489d.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/sns-fifo-throughput-scope.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/sns-fifo-throughput-scope.template.json new file mode 100644 index 0000000000000..7608563be711a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/sns-fifo-throughput-scope.template.json @@ -0,0 +1,54 @@ +{ + "Resources": { + "MessageGroupScopeTopicAB4E2D6F": { + "Type": "AWS::SNS::Topic", + "Properties": { + "FifoThroughputScope": "MessageGroup", + "FifoTopic": true, + "TopicName": "snsfifothroughputscope-MessageGroupScopeTopic-52DE3DD3.fifo" + } + }, + "TopicScopeTopic8DEBB616": { + "Type": "AWS::SNS::Topic", + "Properties": { + "FifoThroughputScope": "Topic", + "FifoTopic": true, + "TopicName": "snsfifothroughputscope-TopicScopeTopic-92BBF542.fifo" + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/snsfifothroughputscopetestDefaultTestDeployAssertBAF90E92.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/snsfifothroughputscopetestDefaultTestDeployAssertBAF90E92.assets.json new file mode 100644 index 0000000000000..ad483902bf0d2 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/snsfifothroughputscopetestDefaultTestDeployAssertBAF90E92.assets.json @@ -0,0 +1,19 @@ +{ + "version": "39.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "snsfifothroughputscopetestDefaultTestDeployAssertBAF90E92.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/snsfifothroughputscopetestDefaultTestDeployAssertBAF90E92.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/snsfifothroughputscopetestDefaultTestDeployAssertBAF90E92.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/snsfifothroughputscopetestDefaultTestDeployAssertBAF90E92.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/tree.json new file mode 100644 index 0000000000000..3d6f075d2cb0f --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.js.snapshot/tree.json @@ -0,0 +1,153 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "sns-fifo-throughput-scope": { + "id": "sns-fifo-throughput-scope", + "path": "sns-fifo-throughput-scope", + "children": { + "MessageGroupScopeTopic": { + "id": "MessageGroupScopeTopic", + "path": "sns-fifo-throughput-scope/MessageGroupScopeTopic", + "children": { + "Resource": { + "id": "Resource", + "path": "sns-fifo-throughput-scope/MessageGroupScopeTopic/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::SNS::Topic", + "aws:cdk:cloudformation:props": { + "fifoThroughputScope": "MessageGroup", + "fifoTopic": true, + "topicName": "snsfifothroughputscope-MessageGroupScopeTopic-52DE3DD3.fifo" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_sns.CfnTopic", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_sns.Topic", + "version": "0.0.0" + } + }, + "TopicScopeTopic": { + "id": "TopicScopeTopic", + "path": "sns-fifo-throughput-scope/TopicScopeTopic", + "children": { + "Resource": { + "id": "Resource", + "path": "sns-fifo-throughput-scope/TopicScopeTopic/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::SNS::Topic", + "aws:cdk:cloudformation:props": { + "fifoThroughputScope": "Topic", + "fifoTopic": true, + "topicName": "snsfifothroughputscope-TopicScopeTopic-92BBF542.fifo" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_sns.CfnTopic", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_sns.Topic", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "sns-fifo-throughput-scope/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "sns-fifo-throughput-scope/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "sns-fifo-throughput-scope-test": { + "id": "sns-fifo-throughput-scope-test", + "path": "sns-fifo-throughput-scope-test", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "sns-fifo-throughput-scope-test/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "sns-fifo-throughput-scope-test/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "sns-fifo-throughput-scope-test/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "sns-fifo-throughput-scope-test/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "sns-fifo-throughput-scope-test/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.ts index 7c41b9ee6c927..7efb9ffb719c7 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns-fifo-throughput-scope.ts @@ -1,4 +1,4 @@ -import { App, Stack, StackProps} from 'aws-cdk-lib'; +import { App, Stack, StackProps } from 'aws-cdk-lib'; import { FifoThroughputScope, Topic } from 'aws-cdk-lib/aws-sns'; import { IntegTest } from '@aws-cdk/integ-tests-alpha'; diff --git a/packages/aws-cdk-lib/aws-sns/README.md b/packages/aws-cdk-lib/aws-sns/README.md index 57534a253119a..ec77935cd3be8 100644 --- a/packages/aws-cdk-lib/aws-sns/README.md +++ b/packages/aws-cdk-lib/aws-sns/README.md @@ -354,7 +354,7 @@ To improve message throughput using high throughput FIFO topics, increasing the For more information, see [High throughput FIFO topics in Amazon SNS](https://docs.aws.amazon.com/sns/latest/dg/fifo-high-throughput.html). -You can configure high-throughput mode for your FIFO topics by setting `fifoThroughputScope` property. +You can configure high-throughput mode for your FIFO topics by setting the `fifoThroughputScope` property: ```ts const topic = new sns.Topic(this, 'MyTopic', { diff --git a/packages/aws-cdk-lib/aws-sns/lib/topic.ts b/packages/aws-cdk-lib/aws-sns/lib/topic.ts index a3b5166c84d7e..aee9d179d94c3 100644 --- a/packages/aws-cdk-lib/aws-sns/lib/topic.ts +++ b/packages/aws-cdk-lib/aws-sns/lib/topic.ts @@ -102,9 +102,9 @@ export interface TopicProps { /** * Specifies the throughput quota and deduplication behavior to apply for the FIFO topic. * - * You can only set this propery when `fifo` is `true`. + * You can only set this property when `fifo` is `true`. * - * @default - None. SNS default setting is FifoThroughputScope.TOPIC + * @default undefined - SNS default setting is FifoThroughputScope.TOPIC */ readonly fifoThroughputScope?: FifoThroughputScope; } From 2a93b92d9396218c38516dac46f79dd1b66c0d82 Mon Sep 17 00:00:00 2001 From: maz Date: Wed, 22 Jan 2025 23:57:09 +0900 Subject: [PATCH 3/5] add validation --- packages/aws-cdk-lib/aws-sns/lib/topic.ts | 3 +++ packages/aws-cdk-lib/aws-sns/test/sns.test.ts | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/aws-cdk-lib/aws-sns/lib/topic.ts b/packages/aws-cdk-lib/aws-sns/lib/topic.ts index aee9d179d94c3..459fd62aeaab8 100644 --- a/packages/aws-cdk-lib/aws-sns/lib/topic.ts +++ b/packages/aws-cdk-lib/aws-sns/lib/topic.ts @@ -292,6 +292,9 @@ export class Topic extends TopicBase { if (props.messageRetentionPeriodInDays && !props.fifo) { throw new Error('`messageRetentionPeriodInDays` is only valid for FIFO SNS topics.'); } + if (props.fifoThroughputScope && !props.fifo) { + throw new Error('`fifoThroughputScope` can only be set for FIFO SNS topics.'); + } if ( props.messageRetentionPeriodInDays !== undefined && !Token.isUnresolved(props.messageRetentionPeriodInDays) diff --git a/packages/aws-cdk-lib/aws-sns/test/sns.test.ts b/packages/aws-cdk-lib/aws-sns/test/sns.test.ts index 2476e9ce31428..700ec97a85b2b 100644 --- a/packages/aws-cdk-lib/aws-sns/test/sns.test.ts +++ b/packages/aws-cdk-lib/aws-sns/test/sns.test.ts @@ -873,5 +873,16 @@ describe('Topic', () => { FifoThroughputScope: fifoThroughputScope, }); }); + + test('throw error when specify fifoThroughputScope to standard topic', () => { + const app = new cdk.App(); + const stack = new cdk.Stack(app); + + expect( + () => new sns.Topic(stack, 'MyTopic', { + fifoThroughputScope: sns.FifoThroughputScope.MESSAGE_GROUP, + }), + ).toThrow('`fifoThroughputScope` can only be set for FIFO SNS topics.'); + }); }); }); From 270892365d86d7b23ae72bf662d6aadbef6959ff Mon Sep 17 00:00:00 2001 From: maz Date: Sat, 25 Jan 2025 14:24:06 +0900 Subject: [PATCH 4/5] ValidationError --- packages/aws-cdk-lib/aws-sns/lib/topic.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/aws-sns/lib/topic.ts b/packages/aws-cdk-lib/aws-sns/lib/topic.ts index cf19d229ffa67..d4c26aa43f2e6 100644 --- a/packages/aws-cdk-lib/aws-sns/lib/topic.ts +++ b/packages/aws-cdk-lib/aws-sns/lib/topic.ts @@ -293,7 +293,7 @@ export class Topic extends TopicBase { throw new ValidationError('`messageRetentionPeriodInDays` is only valid for FIFO SNS topics.', this); } if (props.fifoThroughputScope && !props.fifo) { - throw new Error('`fifoThroughputScope` can only be set for FIFO SNS topics.'); + throw new ValidationError('`fifoThroughputScope` can only be set for FIFO SNS topics.', this); } if ( props.messageRetentionPeriodInDays !== undefined From 22d3a4a91c654e937b945897e5a6c4352bb400b8 Mon Sep 17 00:00:00 2001 From: Matsuda Date: Sun, 26 Jan 2025 09:07:14 +0900 Subject: [PATCH 5/5] Update topic.ts Co-authored-by: Luca Pizzini --- packages/aws-cdk-lib/aws-sns/lib/topic.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/aws-sns/lib/topic.ts b/packages/aws-cdk-lib/aws-sns/lib/topic.ts index d4c26aa43f2e6..fa4ac1fad49d3 100644 --- a/packages/aws-cdk-lib/aws-sns/lib/topic.ts +++ b/packages/aws-cdk-lib/aws-sns/lib/topic.ts @@ -116,7 +116,7 @@ export interface TopicProps { export enum FifoThroughputScope { /** * Topic scope - * - Throughput: 3000 message per second and a bandwidth of 20MB per second. + * - Throughput: 3000 messages per second and a bandwidth of 20MB per second. * - Deduplication: Message deduplication is verified on the entire FIFO topic. */ TOPIC = 'Topic',