How to Schedule Cron Jobs in a Netlify Serverless Function (For Free)

Netlify doesn’t support traditional cron jobs out of the box, but you can still schedule background tasks without spending a cent. This article shows how to create scheduled tasks in a Netlify serverless environment using GitHub Actions or third-party schedulers — keeping everything lean, free, and scalable. Why Use Cron Jobs on Netlify? Use cases include: Sending daily digest emails Database maintenance tasks API polling or caching routines Step 1: Set Up a Netlify Function First, create a serverless function in the netlify/functions directory: // netlify/functions/scheduled-task.js exports.handler = async function () { console.log("Scheduled function ran"); return { statusCode: 200, body: JSON.stringify({ message: "Task complete" }), }; }; Step 2: Trigger It With GitHub Actions This approach requires no changes to Netlify and is totally free if you already use GitHub: # .github/workflows/netlify-cron.yml name: Trigger Netlify Scheduled Task on: schedule: - cron: '0 */1 * * *' # every hour jobs: run-task: runs-on: ubuntu-latest steps: - name: Call Netlify function run: curl https://your-netlify-site.netlify.app/.netlify/functions/scheduled-task Optional: Use an External Scheduler Platforms like Upstash Scheduler or cron-job.org can also be used to ping your function URL on a schedule. These are free and require no code changes. Pros and Cons ✅ Pros Zero infrastructure overhead Free usage tier with GitHub or Upstash Flexible intervals and decoupled logic ⚠️ Cons Relies on external HTTP triggers May face latency if you're expecting exact timing

Apr 22, 2025 - 04:31
 0
How to Schedule Cron Jobs in a Netlify Serverless Function (For Free)

Netlify doesn’t support traditional cron jobs out of the box, but you can still schedule background tasks without spending a cent. This article shows how to create scheduled tasks in a Netlify serverless environment using GitHub Actions or third-party schedulers — keeping everything lean, free, and scalable.

Why Use Cron Jobs on Netlify?

Use cases include:

  • Sending daily digest emails
  • Database maintenance tasks
  • API polling or caching routines

Step 1: Set Up a Netlify Function

First, create a serverless function in the netlify/functions directory:

// netlify/functions/scheduled-task.js
exports.handler = async function () {
  console.log("Scheduled function ran");
  return {
    statusCode: 200,
    body: JSON.stringify({ message: "Task complete" }),
  };
};

Step 2: Trigger It With GitHub Actions

This approach requires no changes to Netlify and is totally free if you already use GitHub:

# .github/workflows/netlify-cron.yml
name: Trigger Netlify Scheduled Task

on:
  schedule:
    - cron: '0 */1 * * *' # every hour

jobs:
  run-task:
    runs-on: ubuntu-latest
    steps:
      - name: Call Netlify function
        run: curl https://your-netlify-site.netlify.app/.netlify/functions/scheduled-task

Optional: Use an External Scheduler

Platforms like Upstash Scheduler or cron-job.org can also be used to ping your function URL on a schedule. These are free and require no code changes.

Pros and Cons

✅ Pros

  • Zero infrastructure overhead
  • Free usage tier with GitHub or Upstash
  • Flexible intervals and decoupled logic

⚠️ Cons

  • Relies on external HTTP triggers
  • May face latency if you're expecting exact timing