Creating CRON Jobs using Amazon Event Bridge

Amir Mustafa
4 min readFeb 5, 2022

→ AWS provides us with a service, to react to the events in AWS.

→ We can trigger CRON jobs after some interval of time or trigger some events at some AWS service state.

→ Initially, the Cloudwatch Event service was used. Event Bridge is the extended feature on top of Cloudwatch Events

Different Use-cases:

a. Schedules CRON Jobs:

We can invoke a Lambda every hour with the help of Event Bridge.

b. Trigger Events:

We can also react to events that happen in AWS services, doing something

eg. we create an account of IAM Root user sign in events which is something to be alarmed off. If someone is using the root account an email will be sent via SNS topic

c. EC2 instance state change: We can also react to EC2 instances being terminated.

Hands-on:

Let us implement the above scenarios:

→ Search Cloudwatch in AWS console

→ Click Rules from the left. Click Go to Amazon EventBridge button

→ We can create multiple rules from here. Click Create rule

A. Event1: Invoking a Lambda in every one hour:

→ Enter the name of your rule, click the Schedule radio button.

→ Here we can give say AWS to trigger every one hour (can be configured in minutes, hours, days)

→ Alternatively, we can also write CRON expression.

→ Here, we select an AWS service to invoke in the above set time. Let us choose Lambda

→ Search your Lambda function (By default demo-lambda will be there)

→ Click Create button

B. Event2: Send Notifications when some logins with the Root account:

→ Enter the rule name. Select Event patterns

→ Select Service provider as AWS. Click Service name dropdown. Here we will choose the AWS service.

→ Search console sign in

→ For Notifications, we use SNS topics. Select Target as SNS topics and topic as an example (we can configure our emails/phone SNS topics here)

→ Click Create

C. Event3: Send Notifications when the EC2 instance is terminated:

→ Enter rule name

→ Chose Event patters and service name as EC2. We can choose any state (say shutting down, terminated, stopping, stopped). Click Create

Deleting Rules

→ It is a good practice to delete the event/rules when their work is done.

→ Select your rule. Click Delete button

Video:

https://youtu.be/QIy8g6OTbTM

Closing Thoughts:

This feature is helpful for us. Sometimes one right log error message can save our day why our application is crashing.

Thank you for reading till the end 🙌 . If you enjoyed this article or learned something new, support me by clicking the share button below to reach more people and/or give me a follow on Twitter to see some other tips, articles, and things I learn about and share there. Happy Learnings !!

--

--

Amir Mustafa

JavaScript Specialist | Consultant | YouTuber 🎬. | AWS ☁️ | Docker 🐳 | Digital Nomad | Human. Connect with me on https://www.linkedin.com/in/amirmustafa1/