Stephane: Now let's discuss CloudWatch Events.
In CloudWatch Events is now EventBridge as well,
but it's still available within CloudWatch,
so let me show you what it is.
With CloudWatch Events, you can intercept events
happening from within AWS services, so all the sources.
For example, you could intercept an EC2 Instance Start,
a CodeBuild Failure, Amazon S3 Events
or Trusted Advisor Events, and you can also intercept
any API call with the CloudTrail integration.
Okay, you could have it also, as well,
instead of intercepting events,
to be on a schedule or a Cron.
For example, you want it to just create an event
every four hours, which is very helpful if you wanted,
for example, to chain that with a Lambda function.
So a JSON payload is going to be created for the event
and then is going to be passed to a target,
and you have so many targets in AWS.
You have compute, such as Lambda, Batch, ECS task.
Integration, such as SQS, SNS, Kinesis Data Streams,
Kinesis Data Firehose.
Orchestration, such as Step Functions,
CodePipeline and CodeBuild.
Maintenance, such as SSM or EC2 Actions.
So CloudWatch Events is a very, very powerful service,
so let's go into the hands-on to see how it works.
So on the left hand side I have my rules, and in my rules
I can now see that CloudWatch Events is now EventBridge,
and EventBridge will be in the next lecture,
has more functionality.
Maybe this will disappear one day, but right now
I just wanna show you the CloudWatch rules
from within this interface.
So you create a rule and you specify an event pattern,
and the service name is going to be EC2,
but, as you can see, you have a lot
of services available in here.
Pretty much every AWS service will have CloudWatch Events
associated with it, it's okay.
But what I want is to look at EC2 and the event type
is going to be EC2 Instance State-change Notification.
So we're saying, okay, for this specific state,
and we can go, for example, to pending,
so anytime any EC2 instance goes into the pending state,
meaning that is going to be launched,
then please create an events, so this is quite handy.
And then we can see the Event Pattern Preview,
so this is what the rule that we've defined here is.
But we can also see the sample events that will be created
out of this, which is a JSON document,
which contains a lot of information around the instance ID,
and the state, and the resources, the region, and so on.
Then for targets, you can define targets and targets can be
many, many different things, as you can see right here,
we have a CreateSnapshot API call,
we have StopInstances API call, you have ECS task,
we have Lambda functions and so on.
But I just want to send myself an email,
so I'll just do SNS topic,
and then we need to select a topic.
So let me just create a topic very quickly.
So I will go into the SNS service, and I will go to Topics
and Create a topic, and this will be a standard topic
called DemoTopic.
We'll create this topic and then I will add a subscription,
so I will add an email subscription.
So the protocol is of type email,
and the end point is stephane@mailinator.com.
We'll create the subscription.
Now we need to verify the subscription,
so for this I will go into the mailintor service,
and then I will go into a mailbox named Stephane
and I will find the subscription confirmation
for my SNS subscription so I'll click on Confirm.
So now the subscription is confirmed.
So back into SNS, if I refresh this
my status of my subscription is confirmed,
so that means that any type of notification
sent into here will be sent into my inbox.
So if I go back to my inbox, and I just delete
this email for now, as you can see, it's currently empty,
so now what I'm going to do is that I'm going to refresh
this page very quickly to make the SNS topic appear.
So back into EC2,
the event is Instance State-change Notification
and pending, and then the target is going to be
an SNS topic and here's the DemoTopic.
And then for the inputs,
we're going to get the entire matched event,
so this entire JSON, right here,
will be sent into my targets.
So I'll click on Configure details, I'll call it DemoRule,
it's enabled, and I will Create this rule.
So this DemoRule was created, okay,
and now if I go into my EC2 console,
and I'm going to just, quickly, create an instance.
So I will launch an instance, Amazon Linux 2,
and I will click on Review and Launch, Launch, and then yes.
This instance is now being initiated, and, as you can see,
the instance state is now Pending.
So we expect this CloudWatch Event rule to be triggered
and send a notification to my DemoTopic,
which will send me an email.
So if I go here, as you can see, I just received an email
and we can see that from within the email
there's a full JSON document here that was sent,
which corresponds to my account ID, the time,
the EC2 instance that it's concerned
and the state that's pending,
so this CloudWatch Event rule works.
And, as we'll see in the next lecture,
EventBridge is a way to get CloudWatch Events
in a separate console, but with more capability, okay,
and the rules that you create from CloudWatch Events
are also going to appear in EventBridge, as you can see,
my DemoRule is right here, but now we have a newer UI
and it could be a little bit clearer
and has more features as you'll see in the next lecture.
Don't forget to take your instance
and terminate it when you're done.
And that's it for CloudWatch Events.
I hope you liked it, and I will see you in the next lecture.