-
Notifications
You must be signed in to change notification settings - Fork 14
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(event-bridge): schedule, whenAny, rename, when without scope, docs #161
Conversation
✅ Deploy Preview for effortless-malabi-1c3e77 ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
src/event-bridge/event-bus.ts
Outdated
* .pipe(func); | ||
* ``` | ||
*/ | ||
all(): EventBusPredicateRuleBase<E>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we going to rename EventBusPredicateRuleBase also? PredicateRuleBase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
src/event-bridge/event-bus.ts
Outdated
} | ||
|
||
/** | ||
* @inheritdoc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess not, I didn't think it would pull the docs in on its own, I guess it does.
src/event-bridge/event-bus.ts
Outdated
* ```ts | ||
* const bus = EventBus.default(scope); | ||
* // every hour | ||
* const everyHour = bus.schedule(scope, 'cron', aws_events.Schedule.rate(Duration.hours(1))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks wrong. schedule is static
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had the docs backwards between the two implementations. Fixed
src/event-bridge/event-bus.ts
Outdated
* | ||
* ```ts | ||
* // every hour | ||
* const everyHour = EventBus.schedule(scope, 'cron', aws_events.Schedule.rate(Duration.hours(1))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could have a simpler interface on top?
Schedule.every(1, "minute").pipe(f)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Later? This would just be a helper? plus there are the other forms, cron
and expression
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, no problem with that. Open an issue to track.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"OnSignUp", | ||
(event) => event["detail-type"] === "SignUp" | ||
); | ||
const defaultBus = EventBus.default(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it require a function call instead of just being static?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Err, there is a parameter for the scope that I missed. will fix.
|
||
Functionless lets you write logic in Typescript on the type safe event. | ||
Event Bus integrates with other AWS Resources via functionless. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this mean?
via Functionless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the authoring integration support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
Functionless supports
putEvents
integrations with other AWS Resources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what that means? Do you mean something like:
The
putEvents
Integration is supported in Lambda Functions (link), Step Functions (link), Appsync Resolvers (link) and API Gateway Integrations (link)
Overall advice is to be more explicit and thorough with documentation.
``` | ||
|
||
What about our young cat lovers? We want to forward those events to our sister team's event bus for processing. | ||
:::caution | ||
Caveat: Events passed to the bus in a step function must be one or more literal objects and may not use the spread (`...`) syntax. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we explain why and perhaps link to an issue?
## Default Event Bus | ||
## Declare an Event Type | ||
|
||
Functionless supports well typed events, lets add our event schema to Typescript. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's define
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this section needs more of an introduction on what Event Types are, rather than just jumping into defining one.
> {} | ||
``` | ||
|
||
## Create an Rule |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Find replace needs to support grammar updates.
|
||
## Put Events from other sources | ||
|
||
Event Bridge Put Events API is one of the methods for putting new events on an event bus. We support some first party integrations between services and event bus. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functionless supports integrations between some AWS services and Event Bridge using the PutEvents API
"myScheduledRule2", | ||
aws_events.Schedule.duration(Duration.hour(1)) | ||
); | ||
// or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or in regular CDK:
const bus = new EventBus(stack, 'bus'); | ||
const allEvents = bus.all('allBusEvents'); | ||
// or | ||
const allEventWhen = bus.when(()) => true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one too many )
const successEvents = sfn.onSucceeded(stack, 'successEvent') | ||
.map(...) // optionally, transform | ||
.pipe(...); // and send somewhere; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is amazing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, its exciting.
.pipe(...); | ||
``` | ||
|
||
Event sources (and all rules) can also be refined: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is redundant, there's a page dedicated to it
@@ -0,0 +1,52 @@ | |||
# Event Sources | |||
|
|||
AWS Step Functions sends [Event Bus events](https://docs.aws.amazon.com/step-functions/latest/dg/cw-events.html) for each machine execution. Functionless provides easy access to them through Event Bus [Event Sources](../event-bridge/event-sources). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you can link to this page from the event bridge event-sources page
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should standardize feature names.
|
To match the labels. |
|
||
[Event Bus Input Transforms](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-transform-target-input.html) transform events matched by [Rules](./rule). | ||
|
||
Functionless allows typescript to be used when defining an input transform. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this?
Functionless translates a purely functional closure into the Event Bus Input Transform JSON format. THis enables you to implement transforms using syntax such as literals and spread expressions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be too complex and technical. Simpler way of saying it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Save that complexity for the syntax page?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we being too redundant by repeatedly explaining how Functionless supports translating TypeScript into XYZ language? Or is it helpful to be redundant on that point?
I also worry that transforms the closure
may be too complicated for average readers. Should we granularly explain what this means with examples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// matches all events. | ||
eventPattern: { source: [{ prefix: "" }] }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps include:
// equivalent to .map(event => event.id)
Is it really though? Why is eventPattern
this?
{ source: [{ prefix: "" }] }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha... that is how you match all events... source
is a required string and prefix: ""
matches any present string.
https://stackoverflow.com/questions/62406933/aws-eventbridge-pattern-to-capture-all-events
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bonkers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment explaining that since this is documentation and it wasn't obvious why/how that happened.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -18,8 +18,6 @@ bus | |||
.pipe(onSignupStepFunction); | |||
``` | |||
|
|||
To jump right into building, see the [`EventBus`](./event-bus.md) documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it because the index page now has a full example and the even bus page is just details about the event bus type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, probably fine. I had it there with the idea that as people read the docs, I wanted to help the jump to the technical resources since the index explained high level overview of the Event Bridge service.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving, but left some comments. Address the ones you think are relevant and then go ahead and merge.
Closes #142, closes #89, closes #140, closes #147
schedule
'd rules Create Schedules on EventBus #140EventBus.default().schedule(scope, id, schedule, props?)
- creates a scheduled rule on the default busEventBus.schedule(scope, id, schedule, props?)
- creates a scheduled rule on the default busall
catch all rule on theEventBus
Support Catch All rule for Event Bus #89bus.all()
- Uses a singleton rule on the event bus, creating a rule callall
.bus.all(scope, id)
- creates a new rule with the scope and id.pipe
escape hatch for unsupported integrations.bus.when().map().pipe((targetInput) => aws_event_targets.LambdaFunction(func, { event: targetInput }))
EventtBusRule
->Rule
EventBusTransform
->EventTransform
EventBusRuleInput
->Event
.when
withoutscope
parameter (when(id, () => {}
)id
(second param)? While possible (I started to do this), we don't want to auto generate CDK resource IDs as small changes would force recreation of the rules, which may disrupt service. This isn't a problem for scope because we always use the bus the rule was created on.bus(event)
tobus.putEvents(event)
.schedule
whenAny
when
patternBREAKING_CHANGE: Event bus integration from
Function
andStepFunction
has been updated to use the patternbus.putEvent(event)
. Previously events were sent by invoking the busbus(event)
.BREAKING_CHANGE: Type names have been changed:
EventtBusRule
->Rule
,EventBusTransform
->EventTransform
,EventBusRuleInput
->Event