Max. 5mins timeout

I am trying to setup serverless for a process that gets triggered by an event, but the task at hand is a bit long - processing a file which can takes upto 30mins sometimes.
However, when setting the timeout to 30mins (1800 seconds) gives the following error-

ServerlessError: An error occurred while provisioning your stack: UploadInvoiceLambdaFunction - 1 validation error detected: Value '1800' at 'timeout' failed to satisfy constraint: Member must have value less than or equal to 300.

Why is the serverless framework adding constraints to variables?

That’s a Lambda constraint, not a Serverless Framework one. From

Q: How long can an AWS Lambda function execute?

All calls made to AWS Lambda must complete execution within 300 seconds. The default timeout is 3 seconds, but you can set the timeout to any value between 1 and 300 seconds.

1 Like

There are two approaches you can take.

  1. Split the file and process it in parallel. For example: You could have one Lambda that reads the file and publishes SNS messages with chunks of the file. Then have another Lambda that reads those messages and processes the data.

  2. Use context.getRemainingTimeInMillis() to find out how long your Lambda has remaining then launch a new Lambda to continue processing.

1 Like