Search code examples
aws-lambdaamazon-ecsserverlessaws-fargate

Fargate vs Lambda, when to use which?


I'm pretty new to the whole Serverless landscape, and am trying to wrap my head around when to use Fargate vs Lambda.

I am aware that Fargate is a serverless subset of ECS, and Lambda is serverless as well but driven by events. But I'd like to be able to explain the two paradigms in simple terms to other folks that are familiar with containers but not that much with AWS and serverless.

Currently we have a couple of physical servers in charge of receiving text files, parsing them out, and populating several db tables with the results. Based on my understanding, I think this would be a use case better suited for Lambda because the process that parses out the text files is triggered by a schedule, is not long running, and ramps down when not in use.

However, if we were to port over one of our servers that receive API calls, we would probably want to use Fargate because we would always need at least one instance of the image up and running.

In terms of containers, and in very general terms would it be safe to say that if the container is designed to do:

docker run <some_input>

Then it is a job for Lambda.

But if the container is designed to do something like:

docker run --expose 80

Then it is a job for Fargate.

Is this a good analogy?


Solution

  • That's the start of a good analogy. However Lambda also has limitations in terms of available CPU and RAM, and a maximum run time of 15 minutes per invocation. So anything that needs more resources, or needs to run for longer than 15 minutes, would be a better fit for Fargate.

    Also I'm not sure why you say something is a better fit for Fargate because you "always need at least one instance running". Lambda+API Gateway is a great fit for API calls. API Gateway is always ready to receive the API call and it will then invoke a Lambda function to process it (if the response isn't already cached).