Besides EC2 instances, which are computers you rent on AWS, AWS offers other ways to run your code, and each one leaves you a different part of the work. With an EC2 instance you pay while it is running, and you also take care of the operating system, its patches and deciding how many instances there are. At the other end is AWS Lambda, where you don't pay for compute on a day when your code doesn't run. Between those two ends are containers and AWS Fargate. For example, an online store can have its website on EC2 and, at the same time, use Lambda for a small job that only runs when a new photo is uploaded.
How much do you manage with each option?

The compute options can be ordered by how many layers AWS manages for you. A layer is each part of what makes your code work: the building and the machines, the operating system, the program that runs the code and the code itself. Going from your own server to EC2, to Fargate and to Lambda, AWS takes on more layers at each step, so you have less to manage and also less control. For example, with its own server the store buys the machine and plugs it in, with EC2 it no longer buys machines but it updates the operating system, and with Lambda it only writes its code.
What is a container?
A container is a package that carries your code together with the libraries it needs to work, but without an operating system of its own, because the containers that run on the same machine share that machine's operating system. That is why a container is lighter than a virtual machine and starts without waiting for a full operating system to load. For example, the store packages the program that calculates the shipping cost in a container, and that container starts in seconds.
Because the container carries everything the code needs, it runs the same way on your laptop, in the test environment and in production, which is where real customers use it. Also, the machine where the containers run can be an EC2 instance, so using containers doesn't force you to leave EC2. For example, the store's developer tests the shipping cost container on their laptop, and that same container, unchanged, later runs on an EC2 instance for customers.
Container services on AWS

AWS has four services for working with containers, and each one covers a different part:
- Amazon ECR (Elastic Container Registry), which stores your container images in private or public repositories and can scan them for vulnerabilities. An image is the package each container comes from, like a mold that identical copies come out of.
- Amazon ECS (Elastic Container Service), which is the AWS container orchestrator, that is, the service that decides where and how many containers run.
- Amazon EKS (Elastic Kubernetes Service), which is managed Kubernetes, where AWS operates the control plane and you use the same Kubernetes tools you would use anywhere else.
- AWS Fargate, which is serverless compute for containers, works with ECS and with EKS, and lets you run containers without provisioning or scaling virtual machines, that is, without setting up machines or deciding how many are needed.
These services are used in order: first you build the image and push it to ECR, and then the orchestrator pulls it and runs it. Finally, you decide where the containers run, which can be on EC2 instances that you manage or on Fargate, where AWS takes care of the servers. For example, the store pushes the shipping cost image to ECR, ECS starts three containers from that image and Fargate provides the machines they run on.
ECS or EKS?
Between ECS and EKS, the difference lies in the tool the team uses. If the team already uses Kubernetes, the option is EKS, and if it wants to get started without learning Kubernetes, the option is ECS. For example, a store whose team has never used Kubernetes starts with ECS, while a bank that already organizes its containers with Kubernetes on its own machines moves to EKS and keeps using the same tools.
What is serverless?
AWS defines serverless as a model where the provider provisions, scales and maintains the servers, and you deploy your code, that is, upload it so it starts working. The servers still exist, but AWS manages them and you don't see them. AWS Fargate, for containers, and AWS Lambda, for code, are serverless services. For example, the store uploads its code to Lambda and never chooses a machine, never updates an operating system and never decides how many machines it needs.
AWS Lambda
AWS Lambda runs your code when something happens, without you provisioning or managing servers. That something that happens is called an event, and the piece of code that runs is called a function. With Lambda you pay only for the compute time you consume, and while your code isn't running there is no charge.

For example, when someone at the store uploads a product photo to an S3 bucket, that event triggers the function that creates the thumbnail, the small version of the photo that appears in the product list. If a thousand photos arrive at the same time, Lambda runs many copies of the function in parallel, and if none arrive, nothing runs. Besides S3, a function can be triggered from Amazon API Gateway, Amazon SQS, Amazon EventBridge and more than 200 services.
Lambda limits
Lambda has two limits that decide whether a task fits in the service:
- Duration, where an invocation, which is each time the function runs, lasts at most 900 seconds, that is, 15 minutes, so a process that takes an hour in a single run doesn't go on Lambda. For example, creating a thumbnail takes little time and fits, but a report that takes an hour doesn't.
- Memory, which is what you choose instead of CPU, from 128 MB to 10,240 MB, and with which CPU grows, so with 1,769 MB the function has the equivalent of one vCPU. For example, if the thumbnail function is slow, you give it more memory and with that it also gets more CPU.
Other compute options

Besides EC2, containers and Lambda, AWS has three compute services for more specific cases:
- Amazon Lightsail, which gives you virtual servers, containers and databases at a predictable monthly price and is the simplest way to set up a WordPress site or a small app. For example, a school puts the website where it posts its announcements there and knows how much it will pay each month.
- AWS Elastic Beanstalk, which takes your web application's code and creates the instances, the load balancing, the scaling (adding or removing instances based on visits) and the health monitoring (checking that each instance responds). For example, the store's developer uploads their code and Beanstalk sets up everything needed for the website to work.
- AWS Batch, which runs batch jobs at any scale, that is, large tasks that are processed all at once and don't have to respond right away. For example, a bank calculates the interest on all its accounts every night with Batch.
How do you recognize each service on the exam?
In compute questions, look in the question for how much the company wants to manage, because "without managing servers" rules out EC2. These are the phrases that point to each service:
- "Containers without managing servers", which points to Fargate.
- "Kubernetes", which points to EKS.
- "Store container images", which points to ECR.
- "Respond to an event", "code that runs for a short time" or "don't pay when it isn't used", which point to Lambda, as long as the process lasts less than 15 minutes.
- "Simple" together with "predictable monthly price", which points to Lightsail.
- "Just upload the code" of a web application, which points to Elastic Beanstalk.
For example, if a question says that a photo app wants to send an email every time a user signs up and doesn't want to pay when nobody signs up, the phrase points to Lambda.
cloud path tip: if you use an account with the new AWS experience, Lambda, ECS, EKS, ECR, Lightsail, Elastic Beanstalk and Batch are included in the free plan.