forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scheduler-targets-alpha):
KinesisDataFirehosePutRecord
Target (a…
…ws#27842) This PR adds KinesisDataFirehosePutRecord as a target for an EventBridge scheduler. Closes aws#27450. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
1 parent
9482952
commit 562ce9b
Showing
14 changed files
with
36,292 additions
and
0 deletions.
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
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 the Firehose delivery stream in region ${this.deliveryStream.stack.region} to the schedule ${Names.nodeUniqueId(schedule.node)} in region ${schedule.env.region}. Both the schedule and the Firehose delivery stream must be in the same region.`); | ||
} | ||
|
||
if (!sameEnvDimension(this.deliveryStream.stack.account, schedule.env.account)) { | ||
throw new Error(`Cannot assign the Firehose delivery stream in account ${this.deliveryStream.stack.account} to the schedule ${Names.nodeUniqueId(schedule.node)} in account ${schedule.env.region}. Both the schedule and the Firehose delivery stream must be in the same account.`); | ||
} | ||
|
||
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.