Add or update site content from Lambda functions

I’m looking to build an 11ty ‘events’ site with one simple (Netlify-) form for each Event's StartDate. Events, StartDates etc. should be content-managed (potentially through Netlify-CMS).

A StartDate has a max number of applicants. When that number is reached, the StartDate is ‘fully-booked’ and visitors should no longer be able to submit that form.

Quite straight forward, it seems…

My challenge is: when applicants submit the form, it should send an email but also update the StartDate

I was thinking of using a Function, running on the submission-created event, but need it to update the proper StartDate (-file) contents, commit and rebuild the 11ty site.

Alternatively it could write/update a JSON file with all submissions or something.

But Functions do not have access to the site’s filesystem (and thus content), correct?

It seems such a common use-case: is there a proper way to achieve this?
(Maybe through a GitLab webhook or something?)

TIA

Hi @davidhund,

While this might be possible, I’d advise against it. A simpler way would be to use a custom serverless function to log the data in an external database and even count the number of applicants in it. Using the same function you can accept/reject more submissions.

The reason why I recommend against it is I don’t think it’s a good idea to update your Git repo from a function - I’m not even considering if it’s possible or not at the moment, but triggering an entire site build just to block form submissions, seems an overkill to me.

if you are still interested in this way more, maybe I can try to look if it’s possible, so let me know.

Thanks for your quick reply. I agree that rebuilding the site simply to block form submissions seems overkill. One of the reasons I was thinking in this direction was because I’d like to reduce dependencies on multiple 3rdparty systems. Ideally I’d not use a DB for this.

Alright, so I gave this a little more thought and it definitely doesn’t seem to be possible with the standard functions, because:

  1. You get a time limit of 10 seconds and even if we max it, it’s still stuck at 26 seconds.
  2. The storage is pretty limited.

Those 2 points would be a problem because to push to your Git repo, you’d have to clone it first. Considering you setup the access rights correctly, you would still have to clone it each time as the storage of functions is volatile. I’m sure 10 seconds or even 26 for that matter won’t be enough - plus it might not have enough space.

You might have some luck with background functions: Background Functions overview | Netlify Docs.

Let me know what you think about this.

Thanks again. You make a good point re: time- and space-limitations. I guess the proper way to deal with this is to involve some 3rd-party DB/API …