Arkinu
AWS service comparison

AWS Fargate vs AWS Lambda: differences and when to use each

AWS Fargate
AWS Lambda

Often confused on the examQuestions tend to offer one as a distractor for the other: look for the phrase in the scenario that tips the balance.

Serverless

AWS Fargate

Technology for running containers with Amazon ECS or Amazon EKS without managing servers or clusters of Amazon EC2 instances. You define the CPU, memory, networking, and permissions for each task or pod, and no longer have to choose server types or scale the cluster.

Exam phrases that point here

  • «run containers without provisioning or managing servers or EC2 instances»

    With Fargate you define the CPU, memory, networking, and permissions of each task (ECS) or pod (EKS), and AWS provides the capacity: there are no instance types to choose, no cluster to scale, and no node operating system to patch.

    When not: If the scenario requires GPUs, control over the instance (your own AMI, SSH access to the node), or Kubernetes DaemonSets, you use ECS or EKS on EC2 instances. If it is not about containers but about short code that reacts to events, think of AWS Lambda.

  • «interruption-tolerant container tasks at the lowest possible cost»

    Fargate Spot runs ECS tasks on spare capacity at a discount compared with the regular Fargate price. AWS can reclaim it with a two-minute warning.

    When not: If the tasks cannot be interrupted, use regular Fargate (and, if usage is steady, Savings Plans). Also, Amazon EKS does not support Fargate Spot: it applies only to Amazon ECS.

  • «each workload must run in isolation, without sharing a kernel, CPU, or memory with others»

    In Fargate each task or pod runs in its own single-use compute environment, with its own kernel, resources, and network interface, separated from the others by a virtualization boundary.

    When not: If the requirement is dedicated physical hardware (for example, for per-socket or per-core licenses), Fargate does not provide it: think of Amazon EC2 Dedicated Hosts.

  • «containers on Fargate need persistent, shared storage»

    A task's or pod's ephemeral storage is erased when it stops, so anything that must persist or be shared across containers is stored in Amazon EFS, which Fargate can mount.

    When not: If the data is needed only while the task is alive (temporary files), ephemeral storage is enough. If it is object data accessed through an API, Amazon S3. On EKS with Fargate, you cannot mount Amazon EBS volumes in pods.

  • «stop managing and patching the nodes of a Kubernetes cluster»

    With Amazon EKS and a Fargate profile, the pods that match the profile run on Fargate: there are no EC2 nodes to create, update, or scale.

    When not: Pods on Fargate do not support DaemonSets, privileged containers, GPUs, or public subnets. If the workload needs any of those, you use EC2 nodes (for example, managed node groups).

Study AWS Fargate →

Serverless

AWS Lambda

Serverless compute service that runs your code without provisioning or managing servers, typically in response to events or API calls from services such as Amazon S3, Amazon SQS, or Amazon EventBridge. AWS manages the infrastructure, scaling, and patching, and you pay only for what you use.

Exam phrases that point here

  • «run code in response to events without provisioning or managing servers»

    Lambda runs your code when an event arrives (an HTTP request, a new object in S3, a message in a queue), scales on its own, and you pay for usage. There are no instances to launch or patch.

    When not: By default, each invocation lasts at most 15 minutes (with Lambda Managed Instances, asynchronous invocations and event source mapping invocations can run up to 90). If a process continuously runs longer than that, or the scenario calls for containers or operating system control, think of AWS Fargate, AWS Batch, or Amazon EC2 (or orchestrating steps with AWS Step Functions).

  • «process each file as soon as it is uploaded to an Amazon S3 bucket»

    S3 can send an event notification to a Lambda function when an object is created or deleted, and it invokes the function asynchronously with the object's data: it is Lambda's most typical trigger.

    When not: If processing each file can exceed the maximum duration of an invocation or is a heavy batch job, AWS Batch or containers on Fargate fit better. And if the function writes to the same bucket that triggers it, it can end up in a loop: use two buckets or an input prefix.

  • «the API must respond with low, consistent latency, without cold starts»

    Provisioned Concurrency keeps a number of execution environments already initialized, so requests do not wait for initialization (the cold start).

    When not: It has an additional cost. If you just need to reduce startup time without strict guarantees, SnapStart is a best-effort optimization; and if the problem is not latency but limiting or securing capacity, the answer is reserved concurrency.

  • «limit how many concurrent executions a function has so it does not overwhelm a downstream system»

    Reserved concurrency sets a maximum (and at the same time a guaranteed minimum) of concurrent executions for a function, at no additional cost. That way the function does not exhaust the account's concurrency or overload whatever is behind it.

    When not: If the goal is to absorb spikes without losing requests, putting an Amazon SQS queue in front decouples the producer from the consumer. Reserved concurrency does not eliminate cold starts: that is what Provisioned Concurrency is for.

  • «the function must query a database located in private subnets of a VPC»

    When you configure the function with the VPC's subnets and security groups, it can reach the private resources in that VPC.

    When not: A function connected to the VPC loses internet access by default. If it also needs to reach the internet, connect it to private subnets whose route table points to a NAT gateway; placing it in a public subnet does not give it internet access.

  • «keep the events that failed after all retries»

    For asynchronous invocations, Lambda retries and, if the attempts run out, it can send the event to an on-failure destination (SQS, SNS, S3, another function, or EventBridge) or to a dead-letter queue (SQS or SNS).

    When not: If the source is an Amazon SQS queue read by Lambda, the dead-letter queue is configured on the queue itself, not on the function. For synchronous invocations (for example, from API Gateway) there are no Lambda retries: the error goes back to the caller.

Often paired with

  • Amazon SQS
  • Amazon DynamoDB
  • Amazon S3
  • Amazon EventBridge
Study AWS Lambda →