How to convert your Lambda Function into a CronJob
- Open the CloudWatch console https://us-west-2.console.aws.amazon.com/cloudwatch/home?region=us-west-2#
- Make sure you’re in your desired region, if not change it
- On the left panel, click on Events —> Rules
- Since CloudWatch Events is now EventBridge, we’ll go to Amazon EventBridge —> https://eu-west-1.console.aws.amazon.com/events/home?region=eu-west-1#/rules
- Click on Create rule
- Give it an appropriate name, usually the same as function name
- At the bottom select the option: Schedule (A rule that runs on time)
- Provide a time interval. Your Lambda Function will execute based on this time interval i.e everyday / every week / every month.
- A cron expression is a combination of 6 values that tell EventBridge when to run the rule. For example cron(0 12 ? *) runs the rule every day at 12:00pm UTC+0.
- Select the Target Type as AWS service
- Select the Target as Lambda function
- Now Select the lambda function, if it’s not there, click on the refresh button right beside or check if you’ve pushed your Lambda function into amplify properly
- Create a tag for easier search later on if you want
- Review all the config and create