How to create a Cloudwatch Event Rule in AWS
A near-real-time stream of system events that describe changes in AWS resources is delivered by CloudWatch Events. We can create a rule that matches events and route them to one or more target functions. We can use CloudWatch Events to schedule automated actions. These actions can be self-triggered at certain times using cron or rate expressions. We can have EC2 instances, Lambda functions, Kinesis Data Streams, ECS tasks, Batch jobs, SNS topics, SQS queues, and a few more services as target endpoints for CloudWatch Events. To know more about Cloudwatch events, visit the official AWS documentation here.
In this document, we will see steps to create an Event Rule with the target as the SNS Topic.
Pre-requisites
- AWS Account (Create if you don’t have one).
- SNS Topic(This will be a target to the Event Rule).
What will we do?
- Login to AWS.
- Create an event rule in Cloudwatch.
Login to AWS
Click here to go to AWS Login Page.
When we hit the above link, we will see a web page as follows where we are required to log in using our login details.
Once you successfully login into AWS, you will see the main dashboard as follows. Click on "Service" at the left top.
Create an event rule in Cloudwatch
Once you click on "Services", search for "Cloudwatch" and then click on the result to go to the Cloudwatch dashboard.
You will see the main dashboard of Cloudwatch as follows. You may or may not see Alarms. Since I already have a few alarms in my region, they are shown on the dashboard.
Click on the "Rules" in the left panel under "Events".
Here, click on "Create rule" to create a new Event Rule.
Click on the "Schedule" radio button and specify a value in the text box in front of "Fixed rate of ". Here "Fixed rate of 5 minutes" means the event will be triggered every 5th minute.
You can choose any of the targets from the list of available options.
In this case, the target we have selected is an "SNS Topic" which will be triggered after every 5 minutes.
Click on "Configure details".
Give a name and description to the event and click on "Create rule".
Once the rule is created, you can see it under the list of available rules.
When you no longer need the event rule, you can either disable the rule or delete it.
To delete the rule permanently, select the rule to be deleted and click on the "Actions" --> "Delete" button
Click on the "Delete" button to confirm the deletion action.
Once the rule is deleted, it can not be restored. This will permanently delete the rule from the account.
Conclusion
In this article, we saw the steps to create an Event Rule which will trigger an SNS Topic every 5 minutes. We also saw how the rule can be deleted.