Search code examples
amazon-web-servicesaws-lambdaaws-api-gatewayamazon-ecsaws-fargate

AWS Fargate suitable for synchronous API?


We are currently using a combo of API Gateway & Lambda to serve some capabilities for our on-prem application. The APIs are synchronous and are invoked from the on-prem application. The Lambda needs to complete quickly for the below reasons-

  • Synchronous AW API would timeout after 30s
  • Users are waiting for the results to come back on the on-prem application. Obviously, we want the waiting time to be small.

The Lambda function involves running K-Means clustering algorithm on a small data set. Currently the Lambda runs for about 13s. We understand that Lambda comes with resource limitation and cannot grow beyond 10GB memory. We are evaluating if the processing can be moved to Fargate. The objective is to overcome the resource limits for future needs and improve runtime.

The problem I see with Fargate is that it has a startup delay- I read that it takes about 60s-90s for the task to start running. Do you recommend Fargate to serve processing for synchronous APIs? I understand we can setup an EC2 and turn off after EU time, but that would be our last option as it would involve lot of operational maintenance.

Also, can Fargate be fully turned off (no charges incurring) during non-business hours?


Solution

  • You would probably need to run the Fargate tasks as an ECS service, such that it runs constantly just like the EC2 instance you are considering. Then there would be no startup delay when requests come in. The ECS service could be scaled down to 0 instances during your non-business hours.