-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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(scheduler-targets-alpha): KinesisStreamPutRecord
Target
#27845
Merged
Merged
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
6f7ad35
feat(scheduler-targets): KinesisStreamPutRecord Target
go-to-k f24b427
chore: rm default
go-to-k bb3b3f7
chore: index
go-to-k 3289cc5
to IStream
go-to-k 2d52200
unit tests
go-to-k 40d4e14
README
go-to-k 441bc6f
change docs
go-to-k c8fe724
WIP in integ tests
go-to-k e6f7934
an integ test
go-to-k f236b54
Revert "README"
go-to-k dbf8918
add to README
go-to-k 5c6ada0
change import/order
go-to-k 7d0450a
change docs in an integ test
go-to-k b963d7e
change order in index.ts and words in README
go-to-k 945604f
change doc for KinesisStreamPutRecordProps
go-to-k 8147258
fix fromStreamArn and add tests
go-to-k 1c99fd6
fix stream.test.ts
go-to-k 77e409e
Merge branch 'main' into scheduler-targets-kinesis-stream
go-to-k ed8b2dd
Merge branch 'main' of https://github.com/go-to-k/aws-cdk into schedu…
go-to-k 1d67e36
Merge branch 'main' into scheduler-targets-kinesis-stream
vinayak-kukreja 1659517
run integ test
vinayak-kukreja 8498c8a
fix conflicts
go-to-k d47f958
Merge branch 'main' into scheduler-targets-kinesis-stream
vinayak-kukreja 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './target'; | ||
export * from './codebuild-start-build'; | ||
export * from './kinesis-stream-put-record'; | ||
export * from './lambda-invoke'; | ||
export * from './stepfunctions-start-execution'; | ||
export * from './codebuild-start-build'; | ||
export * from './target'; |
61 changes: 61 additions & 0 deletions
61
packages/@aws-cdk/aws-scheduler-targets-alpha/lib/kinesis-stream-put-record.ts
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,61 @@ | ||
import { ISchedule, IScheduleTarget, ScheduleTargetConfig } from '@aws-cdk/aws-scheduler-alpha'; | ||
import { Names, Token } from 'aws-cdk-lib'; | ||
import { IRole } from 'aws-cdk-lib/aws-iam'; | ||
import * as kinesis from 'aws-cdk-lib/aws-kinesis'; | ||
import { ScheduleTargetBase, ScheduleTargetBaseProps } from './target'; | ||
import { sameEnvDimension } from './util'; | ||
|
||
/** | ||
* Properties for a Kinesis Data Streams Target | ||
*/ | ||
export interface KinesisStreamPutRecordProps extends ScheduleTargetBaseProps { | ||
/** | ||
* The shard to which EventBridge Scheduler sends the event. | ||
* | ||
* A length of `partitionKey` must be between 1 and 256. | ||
* | ||
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-kinesisparameters.html | ||
*/ | ||
readonly partitionKey: string; | ||
} | ||
|
||
/** | ||
* Use an Amazon Kinesis Data Streams as a target for AWS EventBridge Scheduler. | ||
*/ | ||
export class KinesisStreamPutRecord extends ScheduleTargetBase implements IScheduleTarget { | ||
constructor( | ||
private readonly stream: kinesis.IStream, | ||
private readonly props: KinesisStreamPutRecordProps, | ||
) { | ||
super(props, stream.streamArn); | ||
|
||
if (!Token.isUnresolved(props.partitionKey) && (props.partitionKey.length < 1 || props.partitionKey.length > 256)) { | ||
throw new Error(`partitionKey length must be between 1 and 256, got ${props.partitionKey.length}`); | ||
} | ||
} | ||
|
||
protected addTargetActionToRole(schedule: ISchedule, role: IRole): void { | ||
if (!sameEnvDimension(this.stream.env.region, schedule.env.region)) { | ||
throw new Error(`Cannot assign stream in region ${this.stream.env.region} to the schedule ${Names.nodeUniqueId(schedule.node)} in region ${schedule.env.region}. Both the schedule and the stream must be in the same region.`); | ||
} | ||
|
||
if (!sameEnvDimension(this.stream.env.account, schedule.env.account)) { | ||
throw new Error(`Cannot assign stream in account ${this.stream.env.account} to the schedule ${Names.nodeUniqueId(schedule.node)} in account ${schedule.env.region}. Both the schedule and the stream must be in the same account.`); | ||
} | ||
|
||
if (this.props.role && !sameEnvDimension(this.props.role.env.account, this.stream.env.account)) { | ||
throw new Error(`Cannot grant permission to execution role in account ${this.props.role.env.account} to invoke target ${Names.nodeUniqueId(this.stream.node)} in account ${this.stream.env.account}. Both the target and the execution role must be in the same account.`); | ||
} | ||
|
||
this.stream.grantWrite(role); | ||
} | ||
|
||
protected bindBaseTargetConfig(_schedule: ISchedule): ScheduleTargetConfig { | ||
return { | ||
...super.bindBaseTargetConfig(_schedule), | ||
kinesisParameters: { | ||
partitionKey: this.props.partitionKey, | ||
}, | ||
}; | ||
} | ||
} |
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.