vsfer
vsfer

Reputation: 5

Serverless how to create a function that runs for over 30 seconds on AWS?

everyone,

I am aware that a AWS lambda is only allowed to run for 30 seconds. But I am working on a feature that takes around 2 minutes to finish processing.

In fact I see the end of the request on CloudWatch and nothing is saved to the database. Apparently the API Gateway is closing the lambda execution.

First of all is that correct or am I missing something?

Currently my configuration to declare the function is as following:

api:
    handler: handler.api
    timeout: 30
    events:
      - httpApi: '*'

But as I said 30 seconds isn't enough. Is there a way to create a function that runs for over 30 seconds? What kind of function is that if not an httpApi ? I really need to understand what is the strategy people use when they need a longer exection of lambda functions

Thank you all in advance

Upvotes: -3

Views: 55

Answers (2)

Robert
Robert

Reputation: 20286

This is not possible, but what you can do instead is to schedule a ran with ECS fargate task, it can be triggered like lambda work as much as needed and then be shut down.

The flow should be following

  1. Any event happens (like s3 upload, or SQS message)
  2. Lambda listens to the event and triggers the ECS task
  3. ECS Tasks processes the event without time constraints.

Upvotes: 0

Ninad Gaikwad
Ninad Gaikwad

Reputation: 4480

Max timeout for a lambda function is 15 minutes. You can extend it by going to configuration on the aws console. If you are talking about API limits then yes, api gateway times out in 30 seconds. AWS has recently enabled service quota increase requests for API gateway.

Go to this link after logging in

https://us-east-1.console.aws.amazon.com/servicequotas/home/services/apigateway/quotas/L-E5AE38E3

Request quota increase.

Upvotes: 0

Related Questions