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(event-bridge): schedule, whenAny, rename, when without scope, docs #161

Merged
merged 17 commits into from
Jun 2, 2022

Conversation

thantos
Copy link
Collaborator

@thantos thantos commented May 27, 2022

Closes #142, closes #89, closes #140, closes #147

  • Add schedule'd rules Create Schedules on EventBus #140
    • Can only create schedules rules on the default bus
    • EventBus.default().schedule(scope, id, schedule, props?) - creates a scheduled rule on the default bus
    • EventBus.schedule(scope, id, schedule, props?) - creates a scheduled rule on the default bus
  • Add all catch all rule on the EventBus Support Catch All rule for Event Bus #89
    • bus.all() - Uses a singleton rule on the event bus, creating a rule call all.
    • bus.all(scope, id) - creates a new rule with the scope and id
  • Support .pipe escape hatch for unsupported integrations. bus.when().map().pipe((targetInput) => aws_event_targets.LambdaFunction(func, { event: targetInput }))
  • Rename
    • EventtBusRule ->Rule
    • EventBusTransform -> EventTransform
    • EventBusRuleInput -> Event
  • Support .when without scope parameter (when(id, () => {})
    • Why not support removing 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.
  • Update the integration for putting events to a bus from bus(event) to bus.putEvents(event).
  • Update docs Update docs for EventBus on functionless.org #147
    • Add schedule
    • Add whenAny
    • Add new when pattern
    • Reflect renaming
    • Review all docs and add
    • Integrations
interface MyEventDetails {
   name: string;
}
interface MyEvent extends Event<MyEventDetails, 'myDetailType', 'mySource'>{}
interface LambdaEvent extends Event<{}, string, 'lambda'>{}

const bus = new EventBus<LambdaEvent  | MyEvent>(stack, 'bus');

const allEvents = bus.all();
// transform and then send to lambda
allEvents.map(event => event.id).pipe(new Function(stack, 'func', async (id) => console.log(id)));

const lambdaEvents = bus
   // when the source is lambda
   .when(event => event.source === "lambda")
   // bus to bus
   .pipe(new EventBus());

const logGroup = new aws_logs.LogGroup(this, 'MyLogGroup', {
  logGroupName: 'MyLogGroup',
});

// use the pipe callback escape hatch to pipe to a cloudwatch log group (which functionless doesn't natively support, yet)
bus.when(event => event.source === "lambda")
   .map(event => `log me ${event.id}`)
   .pipe((targetInput) => new targets.CloudWatchLogGroup(logGroup))

const sender = new Function(stack, 'sender', async () => {
   // new pattern to send events from lambda, sfn to an event bus
   bus.putEvents({ source: "mySource", "detail-type": "myDetailType", detail: { name: "SAM" } });
})

BREAKING_CHANGE: Event bus integration from Function and StepFunction has been updated to use the pattern bus.putEvent(event). Previously events were sent by invoking the bus bus(event).
BREAKING_CHANGE: Type names have been changed: EventtBusRule ->Rule, EventBusTransform -> EventTransform, EventBusRuleInput -> Event

@netlify
Copy link

netlify bot commented May 27, 2022

Deploy Preview for effortless-malabi-1c3e77 ready!

Name Link
🔨 Latest commit ff9a3ba
🔍 Latest deploy log https://app.netlify.com/sites/effortless-malabi-1c3e77/deploys/6298ad7a0a902d0008a8bfca
😎 Deploy Preview https://deploy-preview-161--effortless-malabi-1c3e77.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@thantos thantos changed the title Event bus v2 2 feat(EventBus): schedule, whenAny, rename, when without scope May 27, 2022
@thantos thantos changed the title feat(EventBus): schedule, whenAny, rename, when without scope feat(EventBus): schedule, whenAny, rename, when without scope, docs May 27, 2022
* .pipe(func);
* ```
*/
all(): EventBusPredicateRuleBase<E>;
Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure

}

/**
* @inheritdoc
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this necessary?

Copy link
Collaborator Author

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.

* ```ts
* const bus = EventBus.default(scope);
* // every hour
* const everyHour = bus.schedule(scope, 'cron', aws_events.Schedule.rate(Duration.hours(1)));
Copy link
Collaborator

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

Copy link
Collaborator Author

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

*
* ```ts
* // every hour
* const everyHour = EventBus.schedule(scope, 'cron', aws_events.Schedule.rate(Duration.hours(1)));
Copy link
Collaborator

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)

Copy link
Collaborator Author

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.

https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule-schedule.html#eb-rate-expressions

Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

test-app/src/people-events.ts Outdated Show resolved Hide resolved
"OnSignUp",
(event) => event["detail-type"] === "SignUp"
);
const defaultBus = EventBus.default();
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.
Copy link
Collaborator

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

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.
Copy link
Collaborator

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?

website/docs/concepts/event-bridge/event-bus.md Outdated Show resolved Hide resolved
## Default Event Bus
## Declare an Event Type

Functionless supports well typed events, lets add our event schema to Typescript.
Copy link
Contributor

Choose a reason for hiding this comment

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

let's define

Copy link
Collaborator

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a

Copy link
Collaborator Author

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.

website/docs/concepts/event-bridge/index.md Show resolved Hide resolved
website/docs/concepts/event-bridge/index.md Show resolved Hide resolved

## 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.
Copy link
Contributor

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
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

one too many )

Comment on lines +13 to +15
const successEvents = sfn.onSucceeded(stack, 'successEvent')
.map(...) // optionally, transform
.pipe(...); // and send somewhere;
Copy link
Contributor

Choose a reason for hiding this comment

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

this is amazing

Copy link
Collaborator Author

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:
Copy link
Contributor

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).
Copy link
Contributor

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I do, there is a table at the bottom.
image

@sam-goodwin
Copy link
Collaborator

We should standardize feature names.

feat(event-bridge)

@thantos thantos changed the title feat(EventBus): schedule, whenAny, rename, when without scope, docs feat(event-bridge): schedule, whenAny, rename, when without scope, docs May 30, 2022
@thantos
Copy link
Collaborator Author

thantos commented May 30, 2022

We should standardize feature names.

feat(event-bridge)

To match the labels.

@thantos thantos marked this pull request as ready for review May 31, 2022 12:49
website/docs/concepts/event-bridge/rule.md Show resolved Hide resolved
website/docs/concepts/event-bridge/rule.md Outdated Show resolved Hide resolved
website/docs/concepts/event-bridge/transform.md Outdated Show resolved Hide resolved

[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.
Copy link
Collaborator

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.

Copy link
Collaborator

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?

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Attempt 2
image

Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

closure -> code.

Overall, I think its good to callout which features are being aided by compilation.

Gradually explaining, my attempt at that was

image

Comment on lines 32 to 33
// matches all events.
eventPattern: { source: [{ prefix: "" }] },
Copy link
Collaborator

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: "" }] }

Copy link
Collaborator Author

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Bonkers.

Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

image

@@ -18,8 +18,6 @@ bus
.pipe(onSignupStepFunction);
```

To jump right into building, see the [`EventBus`](./event-bus.md) documentation.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why was this removed

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

website/docs/concepts/event-bridge/index.md Outdated Show resolved Hide resolved
website/docs/concepts/event-bridge/index.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@sam-goodwin sam-goodwin left a 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.

@thantos thantos merged commit 82c72d3 into main Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants