Netlify Scheduled Functions let you run code on a schedule without managing any servers, which is pretty neat.

Let’s see one in action. Imagine a function that checks if your site’s RSS feed is still valid, and if not, sends you an email.

// netlify/functions/check-rss.js
import fetch from 'node-fetch';
import { sendEmail } from '../../lib/email'; // Assume this is a helper to send email

const RSS_FEED_URL = 'https://your-website.com/rss.xml';

export const handler = async () => {
  try {
    const response = await fetch(RSS_FEED_URL);
    if (!response.ok) {
      throw new Error(`RSS feed fetch failed: ${response.status} ${response.statusText}`);
    }

    const text = await response.text();
    // Basic check: does it look like XML? You'd want more robust parsing.
    if (!text.trim().startsWith('<?xml')) {
      throw new Error('RSS feed content does not appear to be valid XML.');
    }

    console.log('RSS feed checked successfully.');
    return {
      statusCode: 200,
      body: JSON.stringify({ message: 'RSS feed is valid.' }),
    };
  } catch (error) {
    console.error('Error checking RSS feed:', error);
    await sendEmail({
      to: 'you@example.com',
      subject: 'ALERT: RSS Feed Malfunction!',
      body: `Your RSS feed at ${RSS_FEED_URL} has encountered an error:\n\n${error.message}`,
    });
    return {
      statusCode: 500,
      body: JSON.stringify({ message: 'Error checking RSS feed and sending alert.' }),
    };
  }
};

To make this run on a schedule, you’d create a netlify.toml file in your project’s root:

# netlify.toml

[[functions.schedule]]
  name = "check-rss"
  schedule = "0 8 * * *" # Cron syntax: daily at 8 AM UTC

This netlify.toml tells Netlify to deploy the check-rss.js file as a scheduled function and to execute it according to the specified cron schedule. The function code itself lives in your netlify/functions directory. When the schedule triggers, Netlify invokes this function, passing no event payload by default, and executes the logic within the handler. The return value of the handler function determines the HTTP status code and body of the invocation, though for scheduled functions, this is primarily for logging and debugging within Netlify’s function logs.

The core problem Netlify Scheduled Functions solve is enabling event-driven or time-driven automation without the overhead of server management. Instead of provisioning a VM, configuring a cron daemon, and ensuring it’s always running and accessible, you write a standard Netlify Function and declare its schedule. Netlify handles the underlying infrastructure, scaling, and reliability. This is particularly powerful for tasks like periodic data synchronization, sending out daily/weekly reports, or performing health checks on your application.

Internally, Netlify uses AWS Lambda (or a similar serverless compute service) under the hood. When your netlify.toml defines a scheduled function, Netlify configures an event source (like AWS EventBridge) to trigger your Lambda function at the specified intervals. You don’t see this configuration directly, but it’s how the magic happens. The schedule key in netlify.toml is a direct mapping to cron expressions, allowing for precise control over when your functions run.

The name field in [[functions.schedule]] must exactly match the filename of your function (without the .js extension) in the netlify/functions directory. If you have netlify/functions/my-task.js, the corresponding name in netlify.toml must be my-task. This direct mapping is crucial for Netlify to associate the schedule with the correct function code.

The cron syntax used in netlify.toml is standard. 0 8 * * * means "at minute 0 of hour 8, on every day of the month, on every month, on every day of the week." If you needed it to run every 5 minutes, you’d use */5 * * * *. For a full breakdown of cron syntax, you can refer to standard cron documentation.

A common pitfall is assuming the function runs in your local development environment when you run netlify dev. Scheduled functions are a deployment-time feature. They are triggered by Netlify’s infrastructure on their cloud platform, not by your local netlify dev process. To test the scheduling, you must deploy your site to Netlify and observe the function logs for scheduled executions.

If your scheduled function fails, the next thing you’ll likely encounter is a Function Error notification from Netlify, or you’ll see a 5xx status code when inspecting the function’s execution history in the Netlify UI.

Want structured learning?

Take the full Netlify course →