AWS Certified Solutions Architect – Associate
Lambda vs Fargate vs EC2: choosing compute by cost and workload
Lambda suits short, event-driven tasks of up to 15 minutes, and you pay only while code runs. Fargate runs containers without servers, billed by the CPU and memory you give each task. EC2 gives full control and the most pricing options, but you manage the instances. A Compute Savings Plan discounts all three.
AWS Lambda
Lambda is built for short tasks that keep no state between invocations. One invocation runs for up to 900 seconds (15 minutes). Memory ranges from 128 MB to 10,240 MB, and CPU scales with memory. At 1,769 MB a function has the equivalent of one vCPU.
The /tmp ephemeral storage can be set from 512 MB to 10,240 MB, separately from memory. A function that handles large files can write them to /tmp instead of holding them in memory, so you don't pay for memory it only uses as scratch space.
Work that runs longer than 15 minutes, or runs constantly at high load, is usually a better fit for containers or instances.
AWS Fargate
Fargate runs Amazon ECS tasks without provisioning, patching or scaling EC2 instances. You set CPU and memory per task, and each task gets its own isolation boundary.
Fargate Spot runs interruption-tolerant tasks on spare capacity at a discount. Tasks get a two-minute warning before they are stopped. Fargate does not replace reclaimed Spot capacity with On-Demand capacity, so the service waits until Spot capacity is available again.
Amazon EC2, and paying less for any of them
EC2 fits long-running, steady workloads, special instance types, or software that needs OS access. You pay per second On-Demand, or less with Savings Plans, Reserved Instances or Spot. In exchange, you manage the instances.
A Compute Savings Plan covers EC2, Fargate and Lambda usage, so a team can move a workload between them without losing the discount. An EC2 Instance Savings Plan covers EC2 only. Spot Instances are not covered by Savings Plans.
Savings Plans do not reserve capacity. If a workload needs guaranteed EC2 capacity in one Availability Zone, add a Capacity Reservation.
Where the exam catches people
- Believing Lambda's temporary storage is fixed at 512 MB:
/tmpcan be configured up to 10,240 MB. - Believing large inputs force a Lambda function onto EC2: within the 15-minute limit, more
/tmpand right-sized memory is often the cheaper fix. - Believing Fargate Spot falls back to regular Fargate on its own: Fargate does not replace Spot capacity with on-demand capacity.
- Believing only an EC2 discount can apply to containers and functions: a Compute Savings Plan also covers Fargate and Lambda.