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

feat(scheduler-targets): step function start execution target #27424

Merged
merged 4 commits into from
Oct 11, 2023
Merged

feat(scheduler-targets): step function start execution target #27424

merged 4 commits into from
Oct 11, 2023

Conversation

WtfJoke
Copy link
Contributor

@WtfJoke WtfJoke commented Oct 5, 2023

A StepFunctionStartExecution ScheduleTarget was implemented similar to the already existing LambdaInvoke 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

@aws-cdk-automation aws-cdk-automation requested a review from a team October 5, 2023 23:21
@github-actions github-actions bot added effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Oct 5, 2023
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Oct 6, 2023
Copy link
Contributor

@filletofish filletofish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the commit! It motivated me to add more issues for Scheduler Targets to get help from the community to build all targets for L2 Scheduler constructs.

@@ -0,0 +1,73 @@
function cdk_cli_wrapper_ICdk(p) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like cdk-cli-wrapper folder was committed by mistake?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I commited this by mistake. Good spot! Thanks

/**
* Use an AWS Step function as a target for AWS EventBridge Scheduler.
*/
export class StepFunctionsStartExecution extends ScheduleTargetBase implements IScheduleTarget {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend to add unit tests for this target too. See https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/aws-scheduler-targets-alpha/test/target.test.ts#L9. We probably need to rename that test file and create one file with unit tests per each target.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a new unit test which contains almost identical unit tests for step functions.

I also renamed the existing file target.test.ts into lambda-invoke.test.ts.

@WtfJoke
Copy link
Contributor Author

WtfJoke commented Oct 9, 2023

@filletofish thanks for the review! I'm glad you created more issues for it, I thought about contributing more targets, but have chosen the one I needed the most :)

I've addressed your comments, please have a look on it again.
Thank you!

Comment on lines +20 to +31
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.`);
}
Copy link
Contributor Author

@WtfJoke WtfJoke Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to extract this common logic block somewhere (since its the same for step functions and lambda and probably some targets more, except the message), do you have a favorite spot for it? Should it go to ScheduleTargetBase, in a new class/function or stay "duplicated"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaizencc do you have any opinion on this? I personally do not mind the duplication of the code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind it for now, but would be happy with less duplication :). At best we can create an issue for it and be able to point to it in the future if this gets out of hand

packages/@aws-cdk/aws-scheduler-targets-alpha/README.md Outdated Show resolved Hide resolved
Comment on lines +20 to +31
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.`);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind it for now, but would be happy with less duplication :). At best we can create an issue for it and be able to point to it in the future if this gets out of hand

@kaizencc kaizencc changed the title feat(scheduler-targets): Add step function start execution target feat(scheduler-targets): step function start execution target Oct 11, 2023
Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the submission @WtfJoke!

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Oct 11, 2023
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: d3302f0
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Oct 11, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 3a87141 into aws:main Oct 11, 2023
17 checks passed
@WtfJoke WtfJoke deleted the scheduler-targets-add-step-functions_27377 branch October 11, 2023 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-scheduler-targets-alpha: Add StepFunctionsStartExecution
4 participants