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

docs(@aws-cdk/sns): Convert examples into compiled literate files #107

Merged
merged 4 commits into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 4 additions & 17 deletions packages/@aws-cdk/sns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
4 changes: 4 additions & 0 deletions packages/@aws-cdk/sns/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The files in this directory cannot actually be compiled, because including their
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the cycle?

Does CodeCommit depend on SNS?

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.
Original file line number Diff line number Diff line change
@@ -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());
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down