Run Lambda Function on a Schedule

Lambda functions can run on a scheduled rate and time and triggers can also be set up to run on an event like when a file is uploaded to S3. To run Lambda on a schedule, a trigger needs to be created for Cloudwatch events - a rule needs to created (or selected if one exists) and then then schedule expression will be shown which shows the scheduled rate or time.

To add a trigger to Cloudwatch events, perform the steps as for adding triggers and then select Cloudwatch events as the source.

Once the trigger is added, it will appear in the screen.

In this example, the Lambda function is scheduled to run every 5 minutes. To test if it is running every 5 minutes, open the Cloudwatch logs for the Lambda function and it will be logged every 5 minutes.

The Cloudwatch rule can be viewed by opening the Cloudwatch service page and then clicking Rules on the left menu. The above rule is already and appears as below.

As can be seen, the scheduled time can be setup as cron expression as well. Using the cron expression, the Lambda function can be run at a given time on a given day and / or on a given date. Note that the time needs to be specified in UTC.

Learn more about Cloudwatch Rules and set up the scheduled rate and time.