-
Notifications
You must be signed in to change notification settings - Fork 4k
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): step function start execution target (#27424)
A StepFunctionStartExecution ScheduleTarget was implemented similar to the already existing [LambdaInvoke](https://github.com/aws/aws-cdk/blob/b2a895ef285e5451e64c21e179172e998c479582/packages/%40aws-cdk/aws-scheduler-targets-alpha/lib/lambda-invoke.ts#L8) target. I've added an integration test, which will trigger an eventbridge schedule once. This schedule has a step function as a target. The step function creates a parameter with a given value, which will get verified by the test Closes #27377 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
15 changed files
with
35,577 additions
and
1 deletion.
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,2 +1,3 @@ | ||
export * from './target'; | ||
export * from './lambda-invoke'; | ||
export * from './lambda-invoke'; | ||
export * from './stepfunctions-start-execution'; |
35 changes: 35 additions & 0 deletions
35
packages/@aws-cdk/aws-scheduler-targets-alpha/lib/stepfunctions-start-execution.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,35 @@ | ||
import { IScheduleTarget, ISchedule } from '@aws-cdk/aws-scheduler-alpha'; | ||
import { Names } from 'aws-cdk-lib'; | ||
import { IRole } from 'aws-cdk-lib/aws-iam'; | ||
import { IStateMachine } from 'aws-cdk-lib/aws-stepfunctions'; | ||
import { ScheduleTargetBase, ScheduleTargetBaseProps } from './target'; | ||
import { sameEnvDimension } from './util'; | ||
|
||
/** | ||
* Use an AWS Step function as a target for AWS EventBridge Scheduler. | ||
*/ | ||
export class StepFunctionsStartExecution extends ScheduleTargetBase implements IScheduleTarget { | ||
constructor( | ||
private readonly stateMachine: IStateMachine, | ||
private readonly props: ScheduleTargetBaseProps, | ||
) { | ||
super(props, stateMachine.stateMachineArn); | ||
} | ||
|
||
protected addTargetActionToRole(schedule: ISchedule, role: IRole): void { | ||
const stateMachineEnv = this.stateMachine.env; | ||
if (!sameEnvDimension(stateMachineEnv.region, schedule.env.region)) { | ||
throw new Error(`Cannot assign stateMachine in region ${stateMachineEnv.region} to the schedule ${Names.nodeUniqueId(schedule.node)} in region ${schedule.env.region}. Both the schedule and the stateMachine must be in the same region.`); | ||
} | ||
|
||
if (!sameEnvDimension(stateMachineEnv.account, schedule.env.account)) { | ||
throw new Error(`Cannot assign stateMachine in account ${stateMachineEnv.account} to the schedule ${Names.nodeUniqueId(schedule.node)} in account ${schedule.env.region}. Both the schedule and the stateMachine must be in the same account.`); | ||
} | ||
|
||
if (this.props.role && !sameEnvDimension(this.props.role.env.account, stateMachineEnv.account)) { | ||
throw new Error(`Cannot grant permission to execution role in account ${this.props.role.env.account} to invoke target ${Names.nodeUniqueId(this.stateMachine.node)} in account ${stateMachineEnv.account}. Both the target and the execution role must be in the same account.`); | ||
} | ||
|
||
this.stateMachine.grantStartExecution(role); | ||
} | ||
} |
Oops, something went wrong.