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

feat(sns): support high throughput mode for FIFO topics #33056

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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],
});
20 changes: 20 additions & 0 deletions packages/aws-cdk-lib/aws-sns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
29 changes: 29 additions & 0 deletions packages/aws-cdk-lib/aws-sns/lib/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

/**
Expand Down Expand Up @@ -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, {
Expand Down
20 changes: 20 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 @@ -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,
});
});
});
});
Loading