diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.js.snapshot/SNSInteg.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.js.snapshot/SNSInteg.assets.json index 63d6be8c5fd2c..fd178000c1916 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.js.snapshot/SNSInteg.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.js.snapshot/SNSInteg.assets.json @@ -1,7 +1,7 @@ { "version": "36.0.0", "files": { - "d4f97c865d996fdcf59e005e5e95d931ee98935ca1098865663866fd1ee7b71d": { + "f73578a6268bf972ab72b4905cc09579fd59ece18de3cd0622ff9606ebdcf661": { "source": { "path": "SNSInteg.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "d4f97c865d996fdcf59e005e5e95d931ee98935ca1098865663866fd1ee7b71d.json", + "objectKey": "f73578a6268bf972ab72b4905cc09579fd59ece18de3cd0622ff9606ebdcf661.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.js.snapshot/SNSInteg.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.js.snapshot/SNSInteg.template.json index ef9be119f84b1..6b67cc458f25f 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.js.snapshot/SNSInteg.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.js.snapshot/SNSInteg.template.json @@ -120,6 +120,14 @@ "TopicName": "fooTopicSignatureVersion" } }, + "MyTopicTracingConfigE05AF123": { + "Type": "AWS::SNS::Topic", + "Properties": { + "DisplayName": "fooDisplayNameTracingConfig", + "TopicName": "fooTopicTracingConfig", + "TracingConfig": "Active" + } + }, "MyTopic288CE2107": { "Type": "AWS::SNS::Topic", "Properties": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.js.snapshot/manifest.json index 1a78781843870..f3ce32f94ee6f 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.js.snapshot/manifest.json @@ -18,7 +18,7 @@ "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}/d4f97c865d996fdcf59e005e5e95d931ee98935ca1098865663866fd1ee7b71d.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/f73578a6268bf972ab72b4905cc09579fd59ece18de3cd0622ff9606ebdcf661.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -64,6 +64,12 @@ "data": "MyTopicSignatureVersionEDDB6A3B" } ], + "/SNSInteg/MyTopicTracingConfig/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyTopicTracingConfigE05AF123" + } + ], "/SNSInteg/MyTopic2/Resource": [ { "type": "aws:cdk:logicalId", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.js.snapshot/tree.json index 9bc2212757d6c..752d655b08ecb 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.js.snapshot/tree.json @@ -105,7 +105,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_sns.TopicBase", + "fqn": "aws-cdk-lib.aws_sns.Topic", "version": "0.0.0" } }, @@ -228,7 +228,33 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_sns.TopicBase", + "fqn": "aws-cdk-lib.aws_sns.Topic", + "version": "0.0.0" + } + }, + "MyTopicTracingConfig": { + "id": "MyTopicTracingConfig", + "path": "SNSInteg/MyTopicTracingConfig", + "children": { + "Resource": { + "id": "Resource", + "path": "SNSInteg/MyTopicTracingConfig/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::SNS::Topic", + "aws:cdk:cloudformation:props": { + "displayName": "fooDisplayNameTracingConfig", + "topicName": "fooTopicTracingConfig", + "tracingConfig": "Active" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_sns.CfnTopic", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_sns.Topic", "version": "0.0.0" } }, @@ -259,7 +285,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_sns.TopicBase", + "fqn": "aws-cdk-lib.aws_sns.Topic", "version": "0.0.0" } }, diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.ts index 53a10f66df669..3a24d4e855428 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.ts @@ -1,6 +1,6 @@ import { Key } from 'aws-cdk-lib/aws-kms'; import { App, Stack, StackProps, RemovalPolicy, Duration } from 'aws-cdk-lib'; -import { LoggingProtocol, Topic } from 'aws-cdk-lib/aws-sns'; +import { LoggingProtocol, Topic, TracingConfig } from 'aws-cdk-lib/aws-sns'; import { ManagedPolicy, PolicyDocument, PolicyStatement, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam'; class SNSInteg extends Stack { @@ -51,6 +51,13 @@ class SNSInteg extends Stack { signatureVersion: '2', }); + // Topic with tracingConfig + new Topic(this, 'MyTopicTracingConfig', { + topicName: 'fooTopicTracingConfig', + displayName: 'fooDisplayNameTracingConfig', + tracingConfig: TracingConfig.ACTIVE, + }); + // Can import topic const topic2 = new Topic(this, 'MyTopic2', { topicName: 'fooTopic2', diff --git a/packages/aws-cdk-lib/aws-sns/README.md b/packages/aws-cdk-lib/aws-sns/README.md index de05ba11e95ae..78de0cb3121dd 100644 --- a/packages/aws-cdk-lib/aws-sns/README.md +++ b/packages/aws-cdk-lib/aws-sns/README.md @@ -318,3 +318,19 @@ const topic = new sns.Topic(this, 'MyTopic', { **Note**: The `messageRetentionPeriodInDays` property is only available for FIFO topics. +## TracingConfig + +Tracing mode of an Amazon SNS topic. + +If PassThrough, the topic passes trace headers received from the Amazon SNS publisher to its subscription. +If set to Active, Amazon SNS will vend X-Ray segment data to topic owner account if the sampled flag in the tracing header is true. + +The default TracingConfig is `TracingConfig.PASS_THROUGH`. + +Example with a tracingConfig set to Active: + +```ts +const topic = new sns.Topic(this, 'MyTopic', { + tracingConfig: sns.TracingConfig.ACTIVE, +}); +``` diff --git a/packages/aws-cdk-lib/aws-sns/lib/topic.ts b/packages/aws-cdk-lib/aws-sns/lib/topic.ts index d52babdd5d30e..a57569060be8d 100644 --- a/packages/aws-cdk-lib/aws-sns/lib/topic.ts +++ b/packages/aws-cdk-lib/aws-sns/lib/topic.ts @@ -86,6 +86,15 @@ export interface TopicProps { * @default 1 */ readonly signatureVersion?: string; + + /** + * Tracing mode of an Amazon SNS topic. + * + * @see https://docs.aws.amazon.com/sns/latest/dg/sns-active-tracing.html + * + * @default TracingConfig.PASS_THROUGH + */ + readonly tracingConfig?: TracingConfig; } /** @@ -153,6 +162,21 @@ export enum LoggingProtocol { APPLICATION = 'application', } +/** + * The tracing mode of an Amazon SNS topic + */ +export enum TracingConfig { + /** + * The mode that topic passes trace headers received from the Amazon SNS publisher to its subscription. + */ + PASS_THROUGH = 'PassThrough', + + /** + * The mode that Amazon SNS vend X-Ray segment data to topic owner account if the sampled flag in the tracing header is true. + */ + ACTIVE = 'Active', +} + /** * Represents an SNS topic defined outside of this stack. */ @@ -283,6 +307,7 @@ export class Topic extends TopicBase { fifoTopic: props.fifo, signatureVersion: props.signatureVersion, deliveryStatusLogging: Lazy.any({ produce: () => this.renderLoggingConfigs() }, { omitEmptyArray: true }), + tracingConfig: props.tracingConfig, }); 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 ac3fc5f369084..6c42dd444c441 100644 --- a/packages/aws-cdk-lib/aws-sns/test/sns.test.ts +++ b/packages/aws-cdk-lib/aws-sns/test/sns.test.ts @@ -801,4 +801,22 @@ describe('Topic', () => { ).toThrow('`messageRetentionPeriodInDays` is only valid for FIFO SNS topics'); }); }); + + describe('tracingConfig', () => { + test('specify tracingConfig', () => { + // GIVEN + const app = new cdk.App(); + const stack = new cdk.Stack(app); + + // WHEN + new sns.Topic(stack, 'MyTopic', { + tracingConfig: sns.TracingConfig.ACTIVE, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::SNS::Topic', { + 'TracingConfig': 'Active', + }); + }); + }); });