New to Functions, is there something like crontab?

I do hope my question isn’t too basic, but I couldn’t see an answer in the docs. My static site (Jekyll) has a site heading that I want to change daily. Think of it like quote of the day, and it’s currently stored in _config.yml. If I were doing this the old fashioned way (I’m old!), I’d have a Linux host and use crontab to run a bash script, pull a quote from some website somewhere and stick it into a file (e.g. quote.txt) where my site will read from, then it’ll deploy.

I am thinking Functions / Lambda is ideal for this, but not used it before. I know in AWS I could use CloudWatch events, but what about Netlify? I am on the right track, and can you setup a schedule or would I just use AWS for that?

Not 100% sure about the availability of such an option, but, you can probably trigger a pull request or something using GitHub actions and then Netlify might deploy that. There’s one archived example repo here:

Thanks. AWS Lambda / Functions is great for trigger events, just not cron I guess. I know CloudWatch Events can do it, but when it gets to that stage I might as well just run it from my Linux VPS which I use for a ton of other stuff for $5 a month. Would love to see Netlify add cron triggered Functions!

Hey @neo! :wave:t2:
And welcome to The Community :slight_smile:

There are indeed many ways to make the cookie crumble. If the goal is to simply get a headline on the webpage to change daily and you already know the different values that you’d use for each day, here are a few options:

  • You can have the value statically injected into the markup HTML of the website that gets deployed, meaning that you’d need to determine which headline is appropriate for the given day the build is running, then inject that value; this also implies that you’d want to run the build daily so it can update. As @hrishikesh referred to, GitHub Actions can be your ally there; GHA does allow you to implement tasks on a cron schedule, and your GHA would be pretty simple - it would actually just need to send a web request to a build web-hook from Netlify to prompt Netlify to build your site again (none of the source changed, it just needs to run the build again for each new day).

That admittedly sounds complex. I think there’s an easier way… or maybe a couple.

I would probably make this a front-end task. Something that Javascript could inject into the page for you so that every time the page loads, the javascript can assess what day it is and pull the right data. Even something like adding the following to the bottom of your page’s HTML could suffice:

  const dailyHeadlines = {
    monday: "This is the headline for monday",
    tuesday: "Tuesday is a great day",
    wednesday: "Happy Wednesday!"
  document.getElementById('headline-text-container').innerText = dailyHeadlines[today()]

(that is a rough outline, the function today() is not real but hopefully illustrates the point).

Something like that should load so quickly that users probably wouldn’t ever see the initial text in the headline-text-container object. If you wanted to go further, you could break that object out to its own JSON file and load that as a separate request from the page too. Lots of flexibility.

Hopefully that gives you some ideas!


Can confirm there is no direct support for this today, but it is a popular feature request so maybe someday.

We’ll follow up in this thread if we implement it!