-
Notifications
You must be signed in to change notification settings - Fork 4k
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
aws-cdk-kinesis: Implement Kinesis Stream L2 construct. #86
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*.js | ||
*.js.map | ||
*.d.ts | ||
node_modules | ||
dist | ||
tsconfig.json | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Don't include original .ts files when doing `npm pack` | ||
*.ts | ||
!*.d.ts | ||
coverage | ||
.nyc_output | ||
*.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
## AWS Kinesis Construct Library | ||
|
||
Define an unencrypted Kinesis stream. | ||
|
||
```ts | ||
new Stream(this, 'MyFirstStream'); | ||
``` | ||
|
||
### Encryption | ||
|
||
Define a KMS-encrypted stream: | ||
|
||
```ts | ||
const stream = newStream(this, 'MyEncryptedStream', { | ||
encryption: StreamEncryption.Kms | ||
}); | ||
|
||
// you can access the encryption key: | ||
assert(stream.encryptionKey instanceof kms.EncryptionKey); | ||
``` | ||
|
||
You can also supply your own key: | ||
|
||
```ts | ||
const myKmsKey = new kms.EncryptionKey(this, 'MyKey'); | ||
|
||
const stream = new Stream(this, 'MyEncryptedStream', { | ||
encryption: StreamEncryption.Kms, | ||
encryptionKey: myKmsKey | ||
}); | ||
|
||
assert(stream.encryptionKey === myKmsKey); | ||
``` | ||
|
||
### Importing and Exporting Streams | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be redundant to describe this idiom in every README. @Doug-AWS can you create a doc topic on "importing and exporting constructs across stacks" and have that content there? |
||
|
||
You can create a `Stream` construct that represents an external/existing/unowned stream by using the `Stream.import` factory method. | ||
|
||
This method accepts an object that adheres to `StreamRef`. | ||
|
||
This means that you can define a `StreamRef` using token literals: | ||
|
||
```ts | ||
const stream = Stream.import(this, { | ||
streamArn: new StreamArn('arn:aws:kinesis:us-east-1:123456789012:stream/example-stream-name') | ||
}); | ||
|
||
// now you can just call methods on the stream | ||
stream.grantReadWrite(user); | ||
``` | ||
|
||
The `stream.export()` method can be used to "export" the stream from the current stack. It returns a `StreamRef` object that can later be used in a call to `Stream.import` in another stack. | ||
|
||
Here's an example. | ||
|
||
Let's define a stack with a Kinesis stream and export it using `stream.export()`. | ||
|
||
```ts | ||
class Producer extends Stack { | ||
public readonly myStreamRef: StreamRef; | ||
|
||
constructor(parent: App, name: string) { | ||
super(parent, name); | ||
|
||
const stream = new Stream(this, 'MyStream'); | ||
this.myStreamRef = stream.export(); | ||
} | ||
} | ||
``` | ||
|
||
Now let's define a stack that requires a StreamRef as an input and uses `Stream.import` to create a `Stream` object that represents this external stream. Grant a user principal created within this consuming stack read/write permissions to the stream. | ||
|
||
```ts | ||
interface ConsumerProps { | ||
public userStreamRef: StreamRef; | ||
} | ||
|
||
class Consumer extends Stack { | ||
constructor(parent: App, name: string, props: ConsumerProps) { | ||
super(parent, name); | ||
|
||
const user = new User(this, 'MyUser'); | ||
const userStream = Stream.import(this, props.userStreamRef); | ||
userStream.grantReadWrite(user); | ||
} | ||
} | ||
``` | ||
|
||
Now, let's define our CDK app to bind these together: | ||
|
||
```ts | ||
const app = new App(process.argv); | ||
|
||
const producer = new Producer(app, 'produce'); | ||
|
||
new Consumer(app, 'consume', { | ||
userStreamRef: producer.myStreamRef | ||
}); | ||
|
||
process.stdout.write(app.run()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './stream'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add tslint.json (new)