In the previous article , I have explained in detail on how to Create a Step Function using AWS Console.
In this tutorial , We will learn how to shedule the step function so that it will run the execution automatically at the scheduled time.
To do so , We are going to create Cloudwatch event rule.
What is Cloudwatch Event?
Cloudwatch events provides us a real time stream of system events which helps in describing the recent changes in the resources.
We can create a Event rule which will trigger or start an event to one or more targets.
It helps to track all the changes in the resources and take corrective actions by sending an events such as changing , activating functions and capturing state information.
We can schedule below services that can run at certain times using cron or rate expression .
- Batch job queue
- Code pipeline
- Cloudwatch Log group
- SNS , SQS , Step Function
- Code build , Lambda , EC2 , ECS tasks , Kinesis
- SSM , Firehose delivery stream
Creating Cloudwatch Event Rule
To create a Cloudwatch event rule , Login to CLOUDWATCH CONSOLE
Choose Events in the left Navigation pane , Under Events click Rules
You should see the following page.
To create Rule , Click Create rule
Step 1: Create Rule
We will create rules to invoke targets based on the events occuring in the AWS resources.
Event source can be Event Pattern or Schedule
Choose Schedule , As we are going to schedule the step functions.
You can trigger targets at the fixed rate in Minutes , hours , Days.
If you want to trigger the targets at particular time , Select the Cron expression
If you’re in IST, Convert UTC to IST and provide the expression for Cron.
Once you have provided the cron expression as per you requirement,
Next Under Targets , Click Add Target
In drop down menu , Choose Step function state Machine
Select the State machine you want to trigger
Optionally you can configure inputs if required.
Cloudwatch event rule requires permission to send events to the step function state machine.
You can let it create a role by itself , Or you can choose the existing role.
Also You can add multiple targets to be triggered at the same time.Once added,
Click Configure details,
Step 2 : Configure Rule Details
Under Rule definition , We need to provide a name for the cloudwatch event rule, a description about the rule
And make sure that State is Enabled.
Click Create rule.
You can create multiple event rules if you want to trigger the targets multiple times in a day at a specific time. You can follow the same process.
Now We have successfully created cloudwatch event rules for scheduling step functions to start execution at the specific time as per the Cron expression.
Hope you found it helpful.Thanks for reading this article.
Please do check out my other publications.