Okay, so first let me show you
the CloudWatch Events UI.
So this is CloudWatch Events,
and within CloudWatch, there's Events
and it's going to go away at some point,
so don't be surprised if you don't find it
because now CloudWatch Events is EventBridge,
which is the enhanced version of CloudWatch Events.
So I can go into Amazon EventBridge and look at the new UI.
So in here I get access to multiple things.
So under Event buses,
we have access here to the default event bus.
And this event bus is the one that is created
by default in your account.
And you can already start defining rules on it.
But you can create your own event bus,
and call this one the central event bus,
and I'm recreating, so V2.
You can enable event archives if you wanted to,
to archive these events and retain them forever
in case you wanted to do some debugging,
as well as do automated schema discovery.
And if you needed to get cross-account access
on this event bus, then you could define
a resource-based policy and the templates would be here.
To do so, you would need to edit everything.
So if you don't have a resource-based policy,
then only the event bus owner can send events
to the event bus, which is fine for us.
So let's create this,
and you have created a custom event bus,
and now we're good to go.
So now let's talk about the events.
So we have event sources that can come from partners.
For example, here, we can say
that I want to catch all the events coming from of Auth0.
So we're going to set up
and here is the way to set up your event bus for Auth0.
So there are some instructions to read from
on the Auth0 website.
And then once everything is set up,
then I'm able to catch the events
from Auth0 directly within EventBridge.
So now all the events are captured into EventBridge,
and you need to go ahead and create some rules.
So you need to select Create rule option,
and I'll call this one DemoRuleEventBridge.
And then we select the bus.
So the bus could be default, could be central bus,
or whatever you wanna create, right?
So I'll use a default bus
because it's the one created by default.
And you could either run it on a schedule.
For example, I say,
"Hey, I want this rule to run every hour."
And this could be a way to do a cron in the cloud,
or I wanna run this rule
whenever this specific event happens.
So let's choose the first one.
So next, we have to choose an event source.
And we have a couple of options.
Either we want to have the event source
to be from within AWS, so we choose AWS services,
or this is a custom event or a partner event,
and we would choose Other.
And if you wanted to centralize all your events
in your accounts across accounts,
then you would choose All events
and then you will send that into a central event bus
thanks to resource-based policy.
But for now, we'll choose AWS services,
and next we can filter for sample events.
So this is a feature that is new
and it's called the Sandbox.
So if you go back into Amazon EventBridge
and you go here to the Sandbox,
you can actually test with sample events
and then test against your event pattern
without creating a rule.
But these UI are accessible as well
when you create a rule.
So for sample events, I'm going to select EC2.
And don't get fooled, there's auto scaling here,
but you scroll down and now there's EC2.
And you're going to go
for EC2 State-change notification.
And this is the kind of event
that will get sent into EventBridge
whenever there's a state-change notification.
So we can choose different sample events.
As you can see, this one,
the instant state is in pending,
and this one it's in running, okay?
So let's assume we want to generate events
whenever our instances go into V.
Let's choose the stopping state
because we wanna know whenever they've been stopped.
Okay, stopped, here we go.
So what I'm going to do is scroll down
and create an event pattern.
So I will choose a service provider which is EC2,
and an event type
which is the instance state-change notification.
And we can have all states,
and if I test the pattern right now
is going to match the sample events.
But I can specify a specific state.
For example, only the instances
that have been stopped or terminated.
As you can see, my event pattern just got more granular.
So if we test this right now
is going to match what we had above, which is great.
But if I choose for example, the pending
or the running states and test the pattern again,
it's not going to be cut.
So we know for sure
that the events we are catching right now
are whenever an EC2 instance is stopped or terminated.
Why do we do this?
Well, maybe because whenever that happens
we want to be notified.
So the targets could be either an EventBridge event bus,
which is when you wanna centralize destinations
or an API destination, or you could choose
one of the following AWS services.
And you can see,
you have a lot of possible targets or actions.
But the one that's interesting to me is the SNS topic
because I wanna send into my demo topic,
a message whenever an EC2 instance is stopped or terminated.
So I'll click on Next, Next, and then Review and create.
Yes, my rule looks good.
Let's create this rule.
So now you could try it out
and start to launch an EC2 instance and then terminate it
or stop it and make sure you are subscribed
into your SNS topic with your email,
and then you would receive an email
whenever, well, an instance is stopped or terminated,
which I think is quite nice.
So just to summarize, we have also the archives
to find all the archives of your events, if you needed to,
and the replays to replay events
and put them back into an event bus
to properly fix your integrations.
Finally, you have the schema registry.
So this is a way for you to look at the schema
of these events.
And so for example,
we can look at the AWS event schema registry,
and we type aws.ec2,
and in here you can look at the AWS EC2,
EC2's instant state-change notification.
So it's version one, the schema type is OpenAPI 3.0,
and this is the schema itself right here.
And what this means is that it defines,
well, the possibility of what goes into these events.
So we can see, well, the ID is a string,
the source is a string,
the time is a string in format date-time, and so on.
And this defines how things can be looking
in your event itself.
And thanks to this schema, which was quite complicated,
you can actually download code bindings,
and it's going to generate code for you
for example, in Java, in Python,
in TypeScript or in Go
so that you can manipulate these objects
in a much easier fashion
in your code without writing some manual code for you.
Okay, so that's it for EventBridge.
As you can see, it's a very complete service
with a lot of different features,
but the most important ones
are going to be around setting up rules
and setting up event buses with resource policies.
All right, that's it.
I hope you liked it, and I will see you in the next lecture.