diff --git a/packages/@aws-cdk/sns/README.md b/packages/@aws-cdk/sns/README.md index 4cbe52502eb36..3d841caa1f4ce 100644 --- a/packages/@aws-cdk/sns/README.md +++ b/packages/@aws-cdk/sns/README.md @@ -25,12 +25,7 @@ myTopic.subscribeUrl('MyHttpsSubscription', 'https://foobar.com/'); Subscribe a queue to the topic: -```ts -const myTopic = new Topic(stack, 'MyTopic'); -const queue = new Queue(stack, 'MyQueue'); - -myTopic.subscribeQueue(queue); -``` +[Example of subscribing a queue to a topic](test/integ.sns-sqs.lit.ts) Note that subscriptions of queues in different accounts need to be manually confirmed by reading the initial message from the queue and visiting the link found in it. @@ -39,15 +34,7 @@ reading the initial message from the queue and visiting the link found in it. SNS topics can be used as targets for CloudWatch event rules: -```ts -const myTopic = new Topic(this, 'MyTopic'); -const rule = new EventRule(this, 'Rule', { /* ... */ }); - -rule.addTarget(myTopic); - -// or use as a target in an onXxx method -codeCommitRepo.onCommit('OnCommit', myTopic); -``` +[Example of CloudWatch Event rules](examples/sns-codecommit-event-rule-target.lit.ts) -This will result in adding a target to the event rule and will also modify the topic resource -policy to allow CloudWatch events to publish to the topic. +This will result in adding a target to the event rule and will also modify +the topic resource policy to allow CloudWatch events to publish to the topic. diff --git a/packages/@aws-cdk/sns/examples/README.md b/packages/@aws-cdk/sns/examples/README.md new file mode 100644 index 0000000000000..95ecbec2eafbb --- /dev/null +++ b/packages/@aws-cdk/sns/examples/README.md @@ -0,0 +1,4 @@ +The files in this directory cannot actually be compiled, because including their +dependencies would introduce a dependency cycle. I've put them off to the side +for now, but we should fix this at some point, probably by putting them in a +separate project. diff --git a/packages/@aws-cdk/sns/examples/sns-codecommit-event-rule-target.lit.ts b/packages/@aws-cdk/sns/examples/sns-codecommit-event-rule-target.lit.ts new file mode 100644 index 0000000000000..d44a73fbc463b --- /dev/null +++ b/packages/@aws-cdk/sns/examples/sns-codecommit-event-rule-target.lit.ts @@ -0,0 +1,32 @@ +import { Repository } from '@aws-cdk/codecommit'; +import { App, Stack, StackProps } from "@aws-cdk/core"; +import { EventRule } from "@aws-cdk/events"; +import { Topic } from "../lib"; + +class IntegStack extends Stack { + constructor(parent: App, name: string, props?: StackProps) { + super(parent, name, props); + + const codeCommitRepo = new Repository(this, 'Repo', { + repositoryName: 'TestRepo' + }); + + /// !show + const myTopic = new Topic(this, 'MyTopic'); + + // Use an EventRule and add the topic as a target + const rule = new EventRule(this, 'Rule', { + scheduleExpression: 'rate(1 minute)' + }); + rule.addTarget(myTopic); + + // Or use one of the onXxx methods on event sources + codeCommitRepo.onCommit('OnCommit', myTopic); + + /// !hide + } +} + +const app = new App(process.argv); +new IntegStack(app, 'aws-cdk-sns-event-target'); +process.stdout.write(app.run()); \ No newline at end of file diff --git a/packages/@aws-cdk/sns/test/integ.sns-sqs.expected.json b/packages/@aws-cdk/sns/test/integ.sns-sqs.lit.expected.json similarity index 100% rename from packages/@aws-cdk/sns/test/integ.sns-sqs.expected.json rename to packages/@aws-cdk/sns/test/integ.sns-sqs.lit.expected.json diff --git a/packages/@aws-cdk/sns/test/integ.sns-sqs.ts b/packages/@aws-cdk/sns/test/integ.sns-sqs.lit.ts similarity index 93% rename from packages/@aws-cdk/sns/test/integ.sns-sqs.ts rename to packages/@aws-cdk/sns/test/integ.sns-sqs.lit.ts index c3e7a39fef3e9..d7e0a2699e598 100644 --- a/packages/@aws-cdk/sns/test/integ.sns-sqs.ts +++ b/packages/@aws-cdk/sns/test/integ.sns-sqs.lit.ts @@ -6,10 +6,12 @@ class SnsToSqs extends Stack { constructor(parent: App, name: string, props?: StackProps) { super(parent, name, props); + /// !show const topic = new Topic(this, 'MyTopic'); const queue = new Queue(this, 'MyQueue'); topic.subscribeQueue(queue); + /// !hide } }