Skip to content
Draft: this topic has not been reviewed yet. Check facts against the linked AWS documentation before relying on them.

Containers and serverless compute — ECS, EKS, Fargate and Lambda

Cloud Practitioner · Domain 3 · Cloud Technology and ServicesTask 3.3: Identify AWS compute servicesLevel 118 minComparisonDraft
Difficulty
Confidence

EC2 gives you whole virtual servers. Sometimes you do not want to manage a server at all: you just want your application, or even a single function, to run. AWS offers a range of compute options, from most control to least to manage.

Amazon EC2Virtual serversYou manage the OSECS or EKS on EC2ContainersYou manage the serversAWS FargateContainersNo servers to manageAWS LambdaFunctionsJust your codeMore controlLess to manage (serverless)
Moving right, you manage less and AWS manages more. Moving left, you get more control.

Containers

A container packages an application with everything it needs (code, libraries, settings) into one portable unit. It starts in seconds and runs the same way on a laptop, a test server or in production. Container images are often stored in Amazon Elastic Container Registry (Amazon ECR).

To run many containers you need an orchestrator, which starts containers, restarts failed ones and spreads them across servers. AWS offers two:

Service What it is Choose it when
Amazon Elastic Container Service (Amazon ECS) AWS’s own container orchestrator, simple and deeply integrated with AWS You want the easiest way to run containers on AWS
Amazon Elastic Kubernetes Service (Amazon EKS) Managed Kubernetes, the popular open-source orchestrator You already use Kubernetes, or want the same tools on AWS and elsewhere

Both can run containers on EC2 instances that you manage, or on Fargate.

AWS Fargate: serverless containers

With AWS Fargate, you do not choose, patch or scale any servers for your containers. You say how much CPU and memory each container needs, and Fargate runs it. You pay for the resources your containers request while they run.

Fargate works with both ECS and EKS. It is a good choice when you want containers but not servers.

AWS Lambda: serverless functions

AWS Lambda runs small pieces of code, called functions, in response to events, such as:

  • a file uploaded to an S3 bucket,
  • a request to an API built with Amazon API Gateway,
  • a message arriving in a queue,
  • a schedule (“every night at 2 AM”).

Key facts:

  • No servers to manage: AWS runs, patches and scales everything.
  • Scales automatically from zero to thousands of requests and back.
  • Pay per request and per millisecond of run time. When nothing happens, you pay nothing.
  • A single function run can last up to 15 minutes, so Lambda suits short tasks, not long-running servers.

What “serverless” means

Serverless does not mean there are no servers. It means you do not see or manage them:

  • No servers to provision or patch.
  • Scaling is automatic.
  • You pay only for what you use, with no cost for idle capacity.
  • Availability is built in.

Lambda and Fargate are serverless compute. Other serverless services include Amazon S3, DynamoDB, SQS and SNS.

Choosing compute

Need Choose
Full control of the operating system, or software that must run on a server Amazon EC2
Run containers using Kubernetes Amazon EKS
Run containers the simplest AWS-native way Amazon ECS
Run containers without managing servers AWS Fargate (with ECS or EKS)
Run short code in response to events, pay only when it runs AWS Lambda

Putting it together: a photo app

A photo-sharing app uses several compute options:

  • The main web application runs as containers on ECS with Fargate, so the team never patches servers.
  • When a user uploads a photo to S3, a Lambda function creates a thumbnail in a second or two.
  • A nightly report job runs on Lambda on a schedule.
  • A legacy image-processing tool that needs a special operating system setup runs on EC2.

Common mix-ups

  • ECS vs EKS. Both orchestrate containers; EKS is Kubernetes, ECS is AWS’s own.
  • Fargate vs ECS/EKS. Fargate is not an orchestrator; it is the serverless way to run the containers that ECS or EKS orchestrate.
  • Lambda vs Fargate. Lambda runs short functions triggered by events; Fargate runs containers that can keep running for as long as needed.
  • Serverless still has servers. AWS manages them, not you.

Check yourself

A team wants to run containers but never manage, patch or scale servers. What should it use?

AWS Fargate, with Amazon ECS or Amazon EKS.

A company already uses Kubernetes on premises and wants the same tools on AWS. Which service?

Amazon EKS.

Which service can run code automatically whenever a file is uploaded to S3, charging only while it runs?

AWS Lambda.

Why is Lambda a poor fit for a process that runs for two hours?

A Lambda function can run for at most 15 minutes. A long job suits EC2, Fargate or a batch service.

Key takeaways

  • Containers package an app with its dependencies; ECS and EKS orchestrate them; ECR stores images.
  • Fargate runs containers with no servers to manage; Lambda runs event-driven functions up to 15 minutes.
  • Serverless means no servers for you to manage, automatic scaling and pay-for-use.

Cloud Study Lab is an independent study site. It is not affiliated with or endorsed by Amazon Web Services. AWS and the names of AWS certifications are trademarks of Amazon.com, Inc. or its affiliates.