Skip to content
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-scheduler-targets-alpha: Add StepFunctionsStartExecution #27377

Closed
1 of 2 tasks
WtfJoke opened this issue Oct 2, 2023 · 2 comments · Fixed by #27424
Closed
1 of 2 tasks

aws-scheduler-targets-alpha: Add StepFunctionsStartExecution #27377

WtfJoke opened this issue Oct 2, 2023 · 2 comments · Fixed by #27424
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. hacktoberfest Good issue for hacktoberfest-ers hacktoberfest-accepted PR is accepted for hacktoberfest p2

Comments

@WtfJoke
Copy link
Contributor

WtfJoke commented Oct 2, 2023

Describe the feature

Currently the only impelmentation of IScheduleTarget is LambdaInvoke.

It would be great if we could have also StepFunctionsStartExecution as one of the templated apis in the aws console.

grafik

Use Case

You can have a lot of targets in event scheduler, but in this alpha module its only possible to trigger a lambda. I would like to be able to trigger a Step Function/State Machine from there.

Proposed Solution

The implementation can be very similar/almost identical like LambdaInvoke.

I've tested following implementation in a private project succesfully (heavily inspired by the existing LambdaInvoke code):

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 ${this.stateMachine.env.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 ${this.stateMachine.env.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 ${this.stateMachine.env.account}. Both the target and the execution role must be in the same account.`);
      }

    this.stateMachine.grantStartExecution(role);
  }
}

Other Information

I would like to contribute this feature during the hacktoberfest.
It would be great if this repository can be marked with the topic "hacktoberfest" so that it gets counted towards the goal (see https://hacktoberfest.com/participation/#maintainers for more info) :)

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.99.1

Environment details (OS name and version, etc.)

windows, wsl

@WtfJoke WtfJoke added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Oct 2, 2023
@github-actions github-actions bot added the @aws-cdk/aws-stepfunctions Related to AWS StepFunctions label Oct 2, 2023
@WtfJoke WtfJoke changed the title aws-scheduler-targets-alpha: Add StepFunctionsStartExecution (aws-scheduler-targets-alpha): Add StepFunctionsStartExecution Oct 2, 2023
@WtfJoke WtfJoke changed the title (aws-scheduler-targets-alpha): Add StepFunctionsStartExecution aws-scheduler-targets-alpha: Add StepFunctionsStartExecution Oct 2, 2023
@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Oct 3, 2023
@scanlonp
Copy link
Contributor

scanlonp commented Oct 3, 2023

Hey @WtfJoke, this looks like a great feature to add! We did add hacktoberfest to the topic of this repository this morning, and once you open a PR, we can assign the correct label so it counts for you!

@khushail khushail added p2 effort/small Small work item – less than a day of effort hacktoberfest Good issue for hacktoberfest-ers and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Oct 3, 2023
@mergify mergify bot closed this as completed in #27424 Oct 11, 2023
mergify bot pushed a commit that referenced this issue Oct 11, 2023
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*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@scanlonp scanlonp added the hacktoberfest-accepted PR is accepted for hacktoberfest label Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. hacktoberfest Good issue for hacktoberfest-ers hacktoberfest-accepted PR is accepted for hacktoberfest p2
Projects
None yet
3 participants