Skip to main content

Cron Scheduling for Cloud Resources: Syntax and Pitfalls

A cron expression is a compact way to say 'at these minutes, hours, days and months'. Here is how to read one, how to pair a start with a stop, and where the variants differ.

Cron scheduling is the use of cron expressions, a notation that came from the Unix cron daemon, to describe recurring points in time. For cloud cost work the expression answers one question: at what moments should a resource start, and at what moments should it stop? A schedule is therefore a pair (or a set) of expressions, not a single one: one for the start, one for the stop.

The five standard fields

The format Kubernetes uses for CronJobs, which is also the form ZopNight schedules use, has five space-separated fields:

PositionFieldAllowed values
1minute0 to 59
2hour0 to 23
3day of month1 to 31
4month1 to 12
5day of week0 to 6 (Sunday to Saturday), or sun to sat

An asterisk means “every value”, a hyphen gives a range, and a comma gives a list. The Kubernetes documentation’s own example, 0 3 * * 1, runs weekly on Monday at 3 AM.

Writing a start/stop pair

For an environment used on weekdays from 8 AM to 7 PM:

  • Start: 0 8 * * 1-5 (minute 0, hour 8, Monday to Friday)
  • Stop: 0 19 * * 1-5 (minute 0, hour 19, Monday to Friday)

The stop on Friday evening and the next start on Monday morning leave the weekend off without any extra rule. For a team that also works Saturday mornings, add a second start and stop pair for day 6 rather than widening the weekday rule. Write the stop first when reviewing: it is the expression that saves money, and a wrong stop is the one that interrupts people.

Variants you will meet

Not every cloud service uses the five-field form. Amazon EventBridge Scheduler’s cron expressions have six required fields: minutes, hours, day-of-month, month, day-of-week and year, written as cron(minutes hours day-of-month month day-of-week year). Its day-of-week field runs 1 to 7 (or SUN to SAT), so the numeric day values do not line up with the Kubernetes 0 to 6 range. It also supports ?, L and W wildcards that standard cron lacks. Copying a numeric weekday range between the two formats without converting it shifts the schedule by a day.

Time zones and daylight saving

A cron expression has no time zone of its own; the scheduler supplies one. Kubernetes interprets a CronJob without a time zone relative to the kube-controller-manager’s local time zone, and since v1.27 lets you set .spec.timeZone to a named zone. EventBridge Scheduler accepts a schedule time zone and adjusts for daylight saving automatically: a run that would fall in the skipped spring hour is skipped, and a run in the repeated autumn hour happens only once. If your start time sits inside that hour, the resource can miss a start on the changeover day, so keep start and stop times clear of it.

Suspending instead of deleting

When a cron-driven job should pause for a period, suspension is safer than deletion. A Kubernetes CronJob with .spec.suspend: true keeps its schedule but the controller stops starting new Jobs; Jobs already running are not affected.

How ZopNight uses cron

ZopNight schedules are cron expressions with a name, a description and an IANA time zone, and one schedule can hold several cron strings so its start and stop times live together, for example 0 9 * * 1-5 for a weekday 9 AM start. Before saving, the editor shows a human-readable summary of each expression and a weekly 24-hour grid, which is where overlaps and gaps become visible. For the operational side of choosing windows, see cloud scheduling best practices; to schedule a whole environment at once, see resource groups. A worked example for one service is the EC2 schedule page.

faq

Questions we get a lot.

If yours isn't here, email us and we'll answer directly.

Why does my schedule fire an hour early or late twice a year?

The expression is being evaluated in UTC or in a fixed offset while your team observes daylight saving time. Set a named time zone such as Europe/London on the schedule instead of converting times to UTC by hand.

Can one expression both start and stop a resource?

No. A cron expression only describes moments in time. The action (start or stop) is attached by the scheduler, so a working-hours schedule needs at least one start expression and one stop expression.

Stop watching the waste.
Start cutting it.

See. Find. Fix. Automatic.

Connect your first cloud account in under 5 minutes. See your first remediation in under 7. No credit card required.

CDCR connect detect classify remediate
full audit every action traceable
read-only default access
Multi-cloud automation· Production-ready in 30 min· SOC 2 · ISO 27001· 20–60% off the bill, first month· 4 platforms · 1 console· Multi-cloud automation· Production-ready in 30 min· SOC 2 · ISO 27001· 20–60% off the bill, first month· 4 platforms · 1 console·