Function schedules
Trigger functions according to a schedule
Please contact us if you need access to this feature.
You can define a schedule to automatically invoke functions. For example, you could schedule a function to periodically poll an external API for new inventory data. The Functions UI shows schedules created through the UI and through the SDK on each function’s overview page.
Function schedules are independent from function event bindings. Applying a schedule to a function will cause the function to run on the schedule you specify, regardless of events that trigger the event binding.
Configure a schedule
To configure a schedule:
- Go to the Functions UI.
- Click the function you want to schedule to go to its overview page.
- Click Add schedule.
- Set the schedule.
- Use the Basic tab to define a simple schedule that runs your function after a specific number of minutes, hours, or days.
- Use the Advanced tab to enter a custom
cron
expression.
- Click Create schedule.
Cron expressions (Advanced)
Cron expressions are a powerful way to schedule your function at a specific time or a specific interval. For example, you could use cron
expressions to invoke a function at 8:00 AM (UTC+0
) every first day of the month. The following table shows example cron
expressions.
Expression | Result |
---|---|
cron(15 4 * * MON-FRI) | At 04:15 on every day-of-week from Monday through Friday. |
cron(0 12 1 * *) | At 12:00 on the first day of every month. |
cron(1 8,20 1 * *) | At 8:01 and 20:01 on the first day of every month. |
Syntax
The cron
expression syntax is: cron(minutes hours day-of-month month day-of-week year)
The following table shows the valid values for each field.
Field | Values | Wildcards |
---|---|---|
Minutes | 0-59 | , - * / |
Hours | 0-23 | , - * / |
Day-of-month | 1-31 | , - * ? / L W |
Month | `1-12 or JAN-DEC | , - * / |
Day-of-week | `1-7 or SUN-SAT | , - * ? L # |
Year | 1970 -2199 | , - * / |
Wildcards
- The
,
(comma) wildcard includes additional values. In theMonth
field,JAN
,FEB
,MAR
includes January, February, and March. - The
-
(dash) wildcard specifies ranges. In theDay
field,1-15
includes days1
through15
of the specified month. - The
*
(asterisk) wildcard includes all values in the field. In theHours
field,*
includes every hour. You can’t use*
in both the -Day-of-month
andDay-of-week
fields. If you use it in one, you must use?
in the other. - The
/
(slash) wildcard specifies increments. In theMinutes
field, you could enter1/10
to specify every tenth minute, starting from the first minute of the hour (for example, the 11th, 21st, and 31st minute, and so on). - The
?
(question mark) wildcard specifies any. In theDay-of-month
field you could enter7
and if any day of the week was acceptable, you could enter?
in the Day-of-week field. - The
L
wildcard in theDay-of-month
orDay-of-week
fields specifies the last day of the month or week. - The
W
wildcard in theDay-of-month
field specifies a weekday. In theDay-of-month
field,3W
specifies the weekday closest to the third day of the month. - The
#
wildcard in the Day-of-week field specifies a certain instance of the specified day of the week within a month. For example,3#2
would be the second Tuesday of the month: the3
refers to Tuesday because it is the third day of each week, and the2
refers to the second day of that type within the month.
Restrictions
- Cron expressions that result in your function running faster than once per 1 minute are not supported.
Functions SDK
You can also configure function schedules using the Functions SDK. The SDK allows for more configurabilty than the UI, including:
- Adding more than a single function schedule per Function
- Specifying a timezone other than UTC
- Disabling or enabling a Schedule
- Setting time boundaries.
The following example shows how to set up a functions schedule using the SDK.
SDK schedule expressions
The SDK supports both cron and rate expressions.
Rate expressions
Use rate
expressions to invoke a function at regular intervals. Intervals can be set to run at a specific number of days, hours, or minutes. The following table shows example rate
expressions.
Expression | Result |
---|---|
rate(1 day) | Run the function once a day |
rate(36 hours) | Run the function every 36 hours |
rate(15 minutes) | Run the function every fifteen minutes |