Cloud Technology and Services · Topic 4 of 11

Containers and Serverless Compute

Compare AWS Lambda, ECS, EKS, Fargate, Elastic Beanstalk, Lightsail and Batch, and learn when to choose serverless or container compute over EC2.

  • 4 min
In a nutshell
  • Lambda runs code on events, with no servers to manage, and charges for requests and run time.
  • A Lambda function can run for up to 15 minutes in a single invocation.
  • ECS is AWS's container service. EKS is managed Kubernetes.

What it is

Not every workload needs a virtual server that you manage. AWS offers compute services where AWS handles more of the work.

Containers package an application with everything it needs to run, so it behaves the same everywhere. Serverless means you run code or containers without managing the servers underneath, and you pay for actual use.

The exam asks you to match a described need to the right compute service. The key is how much management you want to do yourself.

EC2you manage serversContainersECS, EKS, FargateLambdayou manage only code

How it works

AWS Lambda

AWS Lambda runs your code in response to events, without any servers for you to manage. Examples of events are a file arriving in Amazon Simple Storage Service (S3), a web request or a schedule.

You pay for the number of requests and the time your code runs, and nothing when it is idle. Lambda functions are meant for short tasks, and a single run has a maximum duration of 15 minutes.

Eventfile uploaded to S3triggersLambdafunction runswritesResultdatabase or bucket

Containers

A container is a lightweight package holding code, libraries and settings. Several containers can share one server, which makes good use of resources.

ServiceWhat it does
Amazon Elastic Container Service (ECS)AWS's own service to run and manage containers
Amazon Elastic Kubernetes Service (EKS)Managed Kubernetes, the open source container orchestrator
AWS FargateServerless compute for containers, with no servers to manage, used with ECS or EKS
Amazon Elastic Container Registry (ECR)Stores and shares container images

Choose ECS for a simple AWS native container setup. Choose EKS when a team already uses Kubernetes or wants a portable setup.

ECS and EKS can run on Elastic Compute Cloud (EC2) instances that you manage, or on Fargate, where AWS manages the servers. Fargate removes the need to pick and patch instances.

Managed application platforms

ServiceWhat it doesChoose when
AWS Elastic BeanstalkYou upload code and it provisions and manages the environmentYou want to deploy a web app quickly without handling the infrastructure details
Amazon LightsailSimple virtual servers, databases and networking with a simple interface and predictable pricingSmall projects, blogs or simple sites
AWS BatchRuns batch computing jobs at any scaleMany jobs that run without a user waiting
AWS App RunnerBuilds and runs web apps and application programming interfaces (APIs) from source or a container imageQuick container web apps with little setup

Lightsail is aimed at beginners and small workloads. It is not the first choice for large, complex designs.

Choosing between compute options

NeedLikely choice
Full control of the operating systemEC2
Run containers and avoid managing serversECS or EKS with Fargate
Run short event driven code with no serversLambda
Deploy a web app with minimum effortElastic Beanstalk
Simple, low cost server for a small siteLightsail

Shared responsibility

As you move from EC2 to containers on Fargate to Lambda, AWS takes on more. With Lambda, AWS manages the servers, operating system and scaling, and you manage the code, its permissions and the data.

Scaling behaviour

Lambda scales automatically as more events arrive, and it scales down to zero cost when nothing happens. ECS and EKS scale the number of containers, which can be paired with Fargate or Auto Scaling for the servers underneath.

What to remember for the exam

  • Lambda runs code on events, with no servers to manage, and charges for requests and run time.
  • A Lambda function can run for up to 15 minutes in a single invocation.
  • ECS is AWS's container service. EKS is managed Kubernetes.
  • Fargate runs containers without servers to manage, and works with ECS and EKS.
  • ECR stores container images.
  • Elastic Beanstalk deploys applications and manages the environment for you.
  • Lightsail is for simple, small workloads with an easy interface.
  • AWS Batch runs batch jobs at scale.
Exam tip

The words "no servers to manage" point to Lambda or Fargate. "Kubernetes" points to EKS. "Upload code and let AWS handle the rest" points to Elastic Beanstalk.

Common mistakes

Calling Fargate a container service on its own. Fargate is the compute engine that runs containers for ECS or EKS.

Using Lambda for long running work. A job that runs longer than the maximum duration needs a different service such as a container.

Thinking serverless has no servers. Servers exist, but AWS manages them.

Confusing ECR with ECS. ECR stores images. ECS runs containers.

Watch out

Lambda is not a good fit for a workload that must run continuously for hours. Pick containers or EC2 instead.

Check yourself

  • Which service runs code in response to events and bills for requests and run time?

    AWS Lambda.

  • What does AWS Fargate remove for container workloads?

    The need to provision and manage the servers that run the containers.

  • Which service is managed Kubernetes?

    Amazon Elastic Kubernetes Service (EKS).

Topic 4 of 11 in Cloud Technology and Services

Test yourself on Cloud Technology and Services

The full AWS CLF-C02 question bank has 832 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by AWS. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.