AI Workshop: learn to build apps with AI →
Netlify: How to set up "cloud cron jobs" using Netlify Scheduled Functions

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


Netlify Scheduled Functions allow us to do some interesting things.

Here’s how to set them up.

Create a serverless function in netlify/functions in your repository, for example test.js:

netlify/functions/test.js

exports.handler = (event, context) => {
  //do something
  return { statusCode: 200 }
}

Then in netlify.toml (create this file if you don’t have it yet) configure how frequently you want this Netlify Scheduled Function to run:

[functions."test"]
schedule = "@hourly"

Alternatively you can set this in the function itself, with no need for this entry:

const handler = (event, context) => {
  //do something
  return { statusCode: 200 }
}

exports.handler = schedule('@hourly', handler)

@hourly runs every hour at minute 0 @daily runs every day at 00:00 @weekly runs every Sunday at 00:00

@monthly and @yearly are available too.

You can also use a cron expression, like 5 4 * * * or any other expression (crontab guru is your friend).

You can also invoke a function manually using netlify functions:invoke test where test is the name of the function.

You can use Netlify Scheduled Functions for many different use cases.

I set a Netlify Scheduled Function to auto-deploy the repository every day to post a scheduled blog post, for which I set the publishing date in advance.

I use the Fetch API to call the deploy webhook so I can do automatic deploys on Netlify.

Lessons in this unit:

0: Introduction
1: Create a Netlify account
2: Deploy to Netlify
3: A tutorial to host your Static Site on Netlify
4: Auto trigger deploys on Netlify
5: Netlify Lambda Functions Tutorial
6: How to use environment variables in Netlify functions
7: How to use npm packages in Netlify Functions
8: How to access query parameters in Netlify functions
9: How to test Netlify Functions locally
10: How to use Netlify Edge Functions
11: ▶︎ How to set up "cloud cron jobs" using Netlify Scheduled Functions
12: How I fixed the trailing slash in Netlify rewrites
13: Durable cache on Netlify
14: How to return HTML from a Netlify function
15: How to use ES modules in Netlify functions
16: How to trigger a Netlify-Vercel-Cloudflare Pages redeploy using a link