Native Support for Scheduled Events added October 8, 2015:
As announced in this AWS blog post, scheduling is now supported as an event source type (also called triggers) called “CloudWatch Events – Schedule“, and can be expressed as a rate or a cron expression.
Add Scheduled Event to a new lambda
Navigate to the ‘Configure triggers’ step of creation, and specify the ‘CloudWatch Event – Schedule’ trigger. Example configuration below:
Add Scheduled Event to an existing lambda
Navigate to the ‘Triggers’ tab of your lambda, select ‘Add Trigger’, and specify the ‘CloudWatch Event – Schedule’ trigger. Example screenshot where I have an existing lambda with an SNS trigger:
Once loaded, the UI to configure this trigger is identical to the screenshot in the above “Add Scheduled Event to a new lambda” section above.
Discussion
For your example case, you’ll want to use cron()
instead of rate()
. Cron expressions in lambda require all fields and are expressed in UTC. So to run a function every day at 5pm (UTC), use the following cron expression:
cron(0 17 * * ? *)
Further Resources
- AWS Documentation – Schedule Expressions Using Rate or Cron
- AWS Documentation – Run an AWS Lambda Function on a Schedule Using the AWS CLI
- AWS Documentation – Tutorial: Using AWS Lambda with Scheduled Events
- AWS has provided a sample “blueprint” that uses a cron expression called
lambda-canary
that can be selected during function creation from the AWS console. - This tutorial walks you through configuration of this blueprint.
- AWS has provided a sample “blueprint” that uses a cron expression called
Notes
- The name of this event type has changed from “Scheduled Event” to “CloudWatch Events – Schedule” since this feature was first released.
- Prior to the release of this feature, the recommended solution to this issue (per “Getting Started with AWS Lambda” at 42min 50secs) was to use SWF to create a timer, or to create a timer with an external application.
- The Lambda UI has been overhauled since the scheduled event blog post came out, and the screenshots within are no longer exact. See my updated screenshots above from 3/10/2017 for latest revisions.