Directly Invoke Background Function

Hi all, I have a background function that runs fine and has been working well for a while now. I’d like to make some changes where I can keep that running but be able to call the function manually, either via the browser or via an external webhook. However, when I put in the function into the browser, a 403 error forbidden is returned. Based on the docs Background Functions overview | Netlify Docs it doesn’t say that an authentication is required. I checked and there’s no basic authentication in place. What else could be causing a 403 error on a background function? Of note, there are other regular functions and hitting them from the browser do not cause 403 errors.

Examples:

  • .netlify/functions/foo works fine in the browser
  • .netfliy/functions/foo-background returns a 403 (note that locally in dev, this invokes the function fine)

Thanks much in advance!

Hi there,

Thanks for reaching out - This is expected behavior; apologies for any inconvenience! Since background functions only return a 202 response to confirm whether they were successfully invoked (as opposed to returning a response with data from the function execution) they aren’t meant to be invoked directly in the browser and will instead throw a 403 error. Please reach out with any questions!

Hi @marcus.little , Thanks much for the assist. Noted about the expected behavior. Question then. Is there a way to invoke a background function from another Netlify function then? If so, could you point me the way to the docs please? The reason is that the function call that we need to call exceeds the 10 second execution limit of a standard function so we have to rely on a background function.

Thanks for following up! This should be possible with Edge Functions, where you can make a passthrough POST request within the EF using something like the fetch API, for example.

Alternatively, we can increase the execution limit for your functions from 10 to 26 seconds, but at that point it’s probably also a good idea to check to see whether there are any opportunities for perf improvements. Please reach out with any questions!

Thank you @marcus.little. Just to be clear, use Edge Functions to invoke a background function?

Thank you for the offer for extending the limit of our functions. However, our execution time is longer than 26 seconds, which is why we switched to using background functions. Thank you for the tips as well for performance improvements. We’ll take a look to be sure but our limitation is primarily third-party dependent rather than our code.

I’m sorry, but this information is not true. You can indeed call a background function from a browser and you would get a 202. The 403 is usually for event-triggered or scheduled functions.

You should not have to do anything with Edge Functions here.