Search code examples
next.jsserverlessbackground-task

How to run functions that take more than 10s on Vercel?


My app periodically runs a function which takes ~20 minutes to run.

This is fine in development. But when I deployed the app on Vercel, the function doesn't complete.

This is because Vercel allows up to 10s limit execution for functions. How can I run this function?


Solution

  • Unfortunately there is not much you can do if you want to keep using nextjs with Vercel. You can host it in aws amplify, but by the time of this answer the lambda functions are not working out of the box with nextjs 12. There are others services out there to help you hosting it in aws, but honestly you should be better of either not using nextjs api routes or, if you really want to use it, create an external app for doing the long process, triggered by the nextjs functions, and request the results to this app or to some database straight from the client side.

    This is Vercel's solution for the problem, which in this situation is not very helpfull https://vercel.com/guides/what-can-i-do-about-vercel-serverless-functions-timing-out