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): eventBridge putEvents target #27629

Merged
merged 4 commits into from
Nov 29, 2023
Merged

feat(scheduler-targets): eventBridge putEvents target #27629

merged 4 commits into from
Nov 29, 2023

Conversation

WtfJoke
Copy link
Contributor

@WtfJoke WtfJoke commented Oct 20, 2023

An eventBridgePutEvents target was implemented similar to the already existing LambdaInvoke/StepFunctionStartExecution target.

I needed to change some properties and methods from Target.ts from private to protected so that the logic could be reused (hope that is ok).

Some design choices to outline (let me know if you disagree or have improvements I could take :) ):

  1. PutEvents would accept multiple Entries (eg. an array), but I decided to support just one single event, because how Target is currently designed (to support only one target arn). It also aligns with the templated integration in the aws management console.
  2. It throws an error in the constructor if the base prop input is used. All the props should be delivered by the new EventBridgePutEventsEntry. It felt not right for the developer experience to split the object (detail to input and source, detailType to EventBridgePutEventsEntry ).

Closes #27454.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added the repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK label Oct 20, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team October 20, 2023 18:13
@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 labels Oct 20, 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 20, 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.

Hi @WtfJoke! Thanks for another scheduler target! A few comments here and there, but I appreciate your dedication to this module :)

schedule: ScheduleExpression.rate(Duration.hours(1)),
target: new targets.EventBridgePutEvents(eventEntry, {}),
});
```
Copy link
Contributor

Choose a reason for hiding this comment

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

theres a section at the top of this readme that mentions what targets are available, can you put this and the stepfunctions one there please

Copy link
Contributor Author

@WtfJoke WtfJoke Oct 28, 2023

Choose a reason for hiding this comment

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

StepFunction was already there. I've added eventbridge. Thanks for pointing this out

@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 23, 2023
@mergify mergify bot dismissed kaizencc’s stale review October 28, 2023 10:19

Pull request has been modified.

@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 28, 2023
@WtfJoke
Copy link
Contributor Author

WtfJoke commented Oct 28, 2023

Hey @kaizencc
Thanks for the review! Appreciate the feedback. I've addressed most of your feedback, please have a look at it again.

Yeah I initially needed StepFunction for a Demo/Talk, so I was keen in contributing this back (after hacking it together on my demo repo) and figured its quiet straight forward to add more targets (Im thinking about adding the Universal target as well, but I could imagine this will be a bit harder) :D

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

3 similar comments
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@WtfJoke
Copy link
Contributor Author

WtfJoke commented Nov 6, 2023

@kaizencc I've fixed the merge conflicts and rebased my changes. Please have a look at it.

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

1 similar comment
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

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.

Hi @WtfJoke, thanks for your continued patience here. I have a few more comments, but this is looking good!

* For example, events by CloudTrail have detail type "AWS API Call via CloudTrail"
* @see https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-events.html
*/
readonly detailType: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can type this better than a string. From the docs you've provided, the only thing that I see as a possible input here is "AWS API Call via CloudTrail". Lol. So here is what I propose:

readonly detailType: DetailType;

////


export class DetailType {
  public static API_CALL_VIA_CLOUDTRAIL() {
    return new DetailType('AWS API Call via CloudTrail');
  }

  public constructor (public readonly type: string) {}
}

This way, we can

a) give users an easy API to hit rather than getting the specific string correct (DetailType.API_CALL_VIA_CLOUDTRAIL),
b) provide space for future additions if we know of other valid detail types as static methods,
c) users can still specify whatever they want via new DetailType('my special type')

Copy link
Contributor Author

@WtfJoke WtfJoke Nov 28, 2023

Choose a reason for hiding this comment

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

Will do.

There seems to be more, but not documented which detail-type they emit.
I found only one additional example in the docs here "detail-type": "EC2 Instance State-change Notification"

Cant speak for others but our team uses only own detail types (e.g your point c).

For context:
I followed the existing EventBridgePutEvents implementation of the step function tasks package, which uses string as type (most likekly the type is identical).

Copy link
Contributor Author

@WtfJoke WtfJoke Nov 28, 2023

Choose a reason for hiding this comment

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

Introduced class DetailType as per request :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Andddd I am now wavering on this suggestion. I still think it could be a good idea, but might be overengineered. I didn't see the nuance at first that most detail-types are user-owned, and then for events from AWS there maybe detail types with specific strings.

I think we should go back to using string here.

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 just dropped my last commit, which effectively reverts the change.

@kaizencc kaizencc changed the title feat(scheduler-targets): Add eventBridge putEvents target feat(scheduler-targets): eventBridge putEvents target Nov 27, 2023
@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 Nov 27, 2023
@mergify mergify bot dismissed kaizencc’s stale review November 28, 2023 23:08

Pull request has been modified.

@WtfJoke WtfJoke requested a review from kaizencc November 28, 2023 23:10
@WtfJoke
Copy link
Contributor Author

WtfJoke commented Nov 28, 2023

@kaizencc Great to hear. Looking forward to getting this merged.

Would be glad if you can answer my questions, as im stuck in 2/3 review comments.

@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 Nov 28, 2023
@WtfJoke
Copy link
Contributor Author

WtfJoke commented Nov 29, 2023

@kaizencc I just dropped my last commit. Also rebased my changes on to latest main and fixed all the conflicts.

Please have a look :)

WtfJoke and others added 3 commits November 29, 2023 21:55
Co-authored-by: Kaizen Conroy <36202692+kaizencc@users.noreply.github.com>
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

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 @WtfJoke and sorry for the many rounds of fruitless reviews :)

Copy link
Contributor

mergify bot commented Nov 29, 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 cd12ce4 into aws:main Nov 29, 2023
10 checks passed
@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 Nov 29, 2023
@WtfJoke
Copy link
Contributor Author

WtfJoke commented Nov 30, 2023

No worries :)

chenjane-dev pushed a commit to chenjane-dev/aws-cdk that referenced this pull request Dec 5, 2023
An eventBridgePutEvents target was implemented similar to the already existing LambdaInvoke/StepFunctionStartExecution target.

I needed to change some properties and methods from Target.ts from private to protected so that the logic could be reused (hope that is ok).

Some design choices to outline (let me know if you disagree or have improvements I could take :) ):
1. PutEvents would accept multiple Entries (eg. an array), but I decided to support just one single event, because how Target is currently designed (to support only one target arn). It also aligns with the templated integration in the aws management console.
2. It throws an error in the constructor if the base prop `input` is used. All the props should be delivered by the new `EventBridgePutEventsEntry`. It felt not right for the developer experience to split the object (detail to `input` and `source`, `detailType` to `EventBridgePutEventsEntry` ).


Closes aws#27454.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-scheduler-targets-alpha): Add EventBridgePutEvents Target
3 participants