-
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
feat(scheduler-targets-alpha): KinesisDataFirehosePutRecord
Target
#27842
Merged
Merged
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f2ca64d
feat(scheduler-targets): KinesisDataFirehosePutRecord Target
go-to-k f4435eb
change an unit test
go-to-k 9547aba
change order in an unit test
go-to-k 18c0b01
fix unit tests
go-to-k 26930d4
rm an integ test
go-to-k 38cf374
add an integ test
go-to-k fb5b027
change an integ test
go-to-k c1214bd
improve an unit test
go-to-k 2cb5cd6
change README and use default value for props
go-to-k 550ddbe
change by the review
go-to-k c6b1563
Merge branch 'main' into feat/scheduler-targets-firehose
go-to-k bbb78fd
Merge branch 'main' of https://github.com/go-to-k/aws-cdk into feat/s…
go-to-k 9490651
Update README.md
go-to-k 3c7e08e
Merge branch 'main' into feat/scheduler-targets-firehose
vinayak-kukreja 45a3ee9
run integ test
vinayak-kukreja 13331b7
fix conflicts
go-to-k 0fba109
Merge branch 'main' of https://github.com/go-to-k/aws-cdk into feat/s…
go-to-k f8d1f44
Merge branch 'main' into feat/scheduler-targets-firehose
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
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -27,6 +27,7 @@ The following targets are supported: | |||||||||||||
1. `targets.LambdaInvoke`: [Invoke an AWS Lambda function](#invoke-a-lambda-function)) | ||||||||||||||
2. `targets.StepFunctionsStartExecution`: [Start an AWS Step Function](#start-an-aws-step-function) | ||||||||||||||
3. `targets.CodeBuildStartBuild`: [Start a CodeBuild job](#start-a-codebuild-job) | ||||||||||||||
4. `targets.KinesisDataFirehosePutRecord`: [Put records to an Amazon Kinesis Data Firehose](#put-records-to-an-amazon-kinesis-data-firehose) | ||||||||||||||
|
||||||||||||||
## Invoke a Lambda function | ||||||||||||||
|
||||||||||||||
|
@@ -121,3 +122,27 @@ new Schedule(this, 'Schedule', { | |||||||||||||
target: new targets.CodeBuildStartBuild(project), | ||||||||||||||
}); | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
## Put records to an Amazon Kinesis Data Firehose | ||||||||||||||
|
||||||||||||||
Use the `KinesisDataFirehosePutRecord` target to put records to an Amazon Kinesis Data Firehose. | ||||||||||||||
|
||||||||||||||
The code snippet below creates an event rule with a delivery stream as a target | ||||||||||||||
called every hour by Event Bridge Scheduler with a custom payload. | ||||||||||||||
|
||||||||||||||
```ts | ||||||||||||||
import * as kinesisfirehose from 'aws-cdk-lib/aws-kinesisfirehose'; | ||||||||||||||
|
||||||||||||||
declare const deliveryStream: kinesisfirehose.CfnDeliveryStream; | ||||||||||||||
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.
Suggested change
|
||||||||||||||
|
||||||||||||||
const payload = { | ||||||||||||||
Data: "record", | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
new Schedule(this, 'Schedule', { | ||||||||||||||
schedule: ScheduleExpression.rate(Duration.minutes(60)), | ||||||||||||||
target: new targets.KinesisDataFirehosePutRecord(deliveryStream, { | ||||||||||||||
input: ScheduleTargetInput.fromObject(payload), | ||||||||||||||
}), | ||||||||||||||
}); | ||||||||||||||
``` |
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-data-firehose-put-record'; | ||
export * from './lambda-invoke'; | ||
export * from './stepfunctions-start-execution'; | ||
export * from './codebuild-start-build'; | ||
export * from './target'; |
37 changes: 37 additions & 0 deletions
37
packages/@aws-cdk/aws-scheduler-targets-alpha/lib/kinesis-data-firehose-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,37 @@ | ||||||
import { ISchedule, IScheduleTarget } from '@aws-cdk/aws-scheduler-alpha'; | ||||||
import { Names } from 'aws-cdk-lib'; | ||||||
import { IRole, PolicyStatement } from 'aws-cdk-lib/aws-iam'; | ||||||
import { CfnDeliveryStream } from 'aws-cdk-lib/aws-kinesisfirehose'; | ||||||
import { ScheduleTargetBase, ScheduleTargetBaseProps } from './target'; | ||||||
import { sameEnvDimension } from './util'; | ||||||
|
||||||
/** | ||||||
* Use an Amazon Kinesis Data Firehose as a target for AWS EventBridge Scheduler. | ||||||
*/ | ||||||
export class KinesisDataFirehosePutRecord extends ScheduleTargetBase implements IScheduleTarget { | ||||||
constructor( | ||||||
private readonly deliveryStream: CfnDeliveryStream, | ||||||
private readonly props: ScheduleTargetBaseProps = {}, | ||||||
) { | ||||||
super(props, deliveryStream.attrArn); | ||||||
} | ||||||
|
||||||
protected addTargetActionToRole(schedule: ISchedule, role: IRole): void { | ||||||
if (!sameEnvDimension(this.deliveryStream.stack.region, schedule.env.region)) { | ||||||
throw new Error(`Cannot assign firehose in region ${this.deliveryStream.stack.region} to the schedule ${Names.nodeUniqueId(schedule.node)} in region ${schedule.env.region}. Both the schedule and the firehose must be in the same region.`); | ||||||
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.
Suggested change
|
||||||
} | ||||||
|
||||||
if (!sameEnvDimension(this.deliveryStream.stack.account, schedule.env.account)) { | ||||||
throw new Error(`Cannot assign firehose in account ${this.deliveryStream.stack.account} to the schedule ${Names.nodeUniqueId(schedule.node)} in account ${schedule.env.region}. Both the schedule and the firehose must be in the same account.`); | ||||||
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.
Suggested change
|
||||||
} | ||||||
|
||||||
if (this.props.role && !sameEnvDimension(this.props.role.env.account, this.deliveryStream.stack.account)) { | ||||||
throw new Error(`Cannot grant permission to execution role in account ${this.props.role.env.account} to invoke target ${Names.nodeUniqueId(this.deliveryStream.node)} in account ${this.deliveryStream.stack.account}. Both the target and the execution role must be in the same account.`); | ||||||
} | ||||||
|
||||||
role.addToPrincipalPolicy(new PolicyStatement({ | ||||||
actions: ['firehose:PutRecord'], | ||||||
resources: [this.deliveryStream.attrArn], | ||||||
})); | ||||||
} | ||||||
} |
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.