
AWS Compute Explained: EC2 vs ECS vs EKS vs Fargate vs Lambda Which Should You Actually Use?
Choosing AWS compute is not just about performance. It is about control, scaling, security, operational effort, and what you actually pay for.
Series: Skill Builder Digital Classroom - AWS Cloud Technical Essentials (11 articles)
- …
- 3AWS Compute Explained: EC2 vs ECS vs EKS vs Fargate vs Lambda Which Should You Actually Use? This article
The most expensive mistake in cloud computing isn't choosing an expensive server. It's choosing a server you never needed.
Imagine running an EC2 instance around the clock to process a spreadsheet that arrives once every three months. The application works. The server is healthy. But compute is running even when there is nothing to process.
Now imagine using AWS Lambda to process the spreadsheet when it lands in Amazon S3. Same business outcome, different architecture and potentially far less infrastructure to maintain.
That's why the first question in cloud design should not be Which AWS service is most powerful? It should be What does this workload actually need?
Amazon EC2, Amazon ECS, Amazon EKS, AWS Fargate, and AWS Lambda help answer that question, but they operate at different layers. Let's separate those layers before choosing among them.

1. Compute as a Service: Stop Buying Servers. Start Buying Capacity.
Traditional infrastructure creates an early commitment. Before an application serves its first user, a team may have to forecast demand, buy hardware, wait for delivery, install servers, configure networks, and arrange physical security and maintenance. When traffic grows unexpectedly, adding capacity can require another procurement cycle. When demand falls, the purchased equipment still exists.
AWS changes that model. Instead of owning physical servers, you can provision computing capacity through the console, APIs, automation tools, or infrastructure-as-code workflows. AWS manages the facilities, host hardware, and foundational cloud infrastructure; you select a service and configure the parts of the environment that remain your responsibility.
That provides three advantages: speed to provision resources, flexibility to change capacity, and cost control when consumption can be matched to demand. Cloud pricing is not automatically cheaper, however. An oversized instance or an unnecessary always-on service can waste money just as physical infrastructure can.
The basic client-server model still applies. A browser or other client sends an HTTP/API request; software such as Nginx, Apache, or IIS receives it; the application processes the request using CPU, memory, storage, and networking resources; and a response returns to the client. Cloud computing changes how those resources are supplied and managed, not the need for them.
Three broad approaches help frame the choices: virtual machines, containers, and serverless execution. Which one is appropriate depends on the application not on which term sounds newer.

2. Amazon EC2: Control Over a Virtual Server
Amazon Elastic Compute Cloud (EC2) provides virtual servers called instances. You can choose the operating system, instance type, storage, network placement, and software running inside the guest OS. AWS manages the underlying physical infrastructure; you manage the instance's OS, patches, applications, and much of its security configuration.
EC2 is a strong option when a workload needs operating-system control, specific software dependencies, or a straightforward migration from existing servers. It is not necessarily the best choice for a process that only runs occasionally.
The AMI: A starting blueprint
An Amazon Machine Image (AMI) defines an instance's starting environment: its OS image, block-device mapping, architecture, launch permissions, and any preinstalled software. An AMI has a Region-specific ID beginning with
ami- .You can select AWS-provided images, approved Marketplace images, community images, or your own customized images. EC2 Image Builder can help teams create and maintain standardized images. One approved image can be used to launch multiple instances, but later software and configuration changes can still cause them to diverge.
For new Amazon Linux deployments, Amazon Linux 2023 is a supported starting point. Amazon Linux 2 reached end of life on June 30, 2026; older course examples using it should not be copied uncritically into new deployments.
The instance type: A resource profile
An EC2 instance type determines a combination of virtual CPU, memory, storage, and networking capabilities.
Instance family | Resource emphasis | Typical workload |
|---|---|---|
General purpose | Balanced CPU and memory | Web and application servers |
Compute optimized | More compute per unit of memory | Batch processing and compute-heavy applications |
Memory optimized | Large memory capacity | In-memory databases and caching |
Storage optimized | Fast local storage and I/O | Data-intensive systems |
Accelerated computing | GPU or specialized acceleration | ML, rendering, specialized processing |
HPC optimized | High-performance computing | Large scientific simulations |
For example,
c5n.xlarge breaks into c (compute-optimized family), 5 (generation), n (network-focused capability), and xlarge (size). A name such as c7gn.xlarge also identifies a Graviton-based processor family. Processor architecture matters: software built only for x86-64 might not run unchanged on Arm-based instances.You can create and manage instances through the AWS Console, CLI, SDKs, or infrastructure automation. Some instance changes require stopping the instance or planning for replacement; they are not always risk-free, instant modifications.
The best instance is not the biggest one. It is the one that matches the workload's measured requirements.

3. EC2 Lifecycle: Understand What Survives and What Costs Money
An instance typically moves from pending to running, and can then be rebooted, stopped, hibernated where supported, or terminated.
Action | What it means | What to remember |
|---|---|---|
Reboot | Restart the guest OS | Instance continues running; compute billing continues |
Stop | Shut down an eligible EBS-backed instance | RAM and instance-store data do not survive; EBS volumes normally persist |
Hibernate | Save RAM contents to the EBS root volume, where supported | Requires supported configuration and sufficient encrypted storage |
Terminate | Permanently end the instance | It cannot be restarted; volumes marked for deletion are removed |
A normal reboot generally retains an instance's IP addresses. A stop/start normally preserves its primary private IPv4 address but replaces an automatically assigned public IPv4 address. An allocated Elastic IP can provide a more persistent public address, subject to its configuration and charges.
Stopping an instance does not necessarily stop the entire bill. Standard EC2 instance usage charges cease when an eligible instance is stopped, but attached EBS volumes, snapshots, public IPv4 addresses, and other resources may continue to incur charges. Hibernation also has additional storage and transition considerations.
There is another operational choice: repair in place or replace. Teams can update a server directly, or create a new instance from an updated, approved image and replace an unhealthy or outdated instance. Replacement can reduce configuration drift when the application is designed for it; stateful workloads need special care. EC2 termination protection can also help guard against accidental termination, but it is not a backup or recovery strategy.

4. Networking and Availability: One Server Is a Single Point of Failure
An online store running on a single instance can go offline when that instance fails. Making the instance larger might increase capacity, but it does not eliminate the failure point. Reliability starts with network design, workload placement, and recovery behavior.
What a VPC actually controls
Every EC2 instance runs inside an Amazon Virtual Private Cloud (VPC). A VPC defines a logically isolated network with subnets, route tables, and security controls. A default VPC is convenient for experiments, but it is not inherently insecure merely because it is the default.
In a typical default VPC, subnets have routes to an Internet Gateway and automatically assign public IPv4 addresses. Yet an instance is not publicly reachable solely because its subnet has an internet route. Addressing, Security Group rules, Network ACLs, and the application listening on a port all matter.
A common production design uses public subnets for internet-facing load balancers and private subnets for application servers and databases that do not need direct inbound access. Private workloads needing outbound connectivity may use NAT or suitable VPC endpoints, depending on what they must reach.
Security Groups are stateful rules applied to associated network interfaces: permitted response traffic is handled automatically. Network ACLs are stateless subnet-level rules: return traffic must also be permitted, and rule order matters. These controls complement one another; neither replaces secure application configuration.
Multi-AZ does not automatically mean highly available
A common resilience pattern distributes application instances across at least two Availability Zones (AZs). An Application Load Balancer can check health and route traffic to healthy targets; an Auto Scaling group can maintain capacity and replace unhealthy EC2 instances.
But two instances alone are insufficient if both rely on a single database, store critical sessions locally, or share another unprotected dependency. Application state, data persistence, networking, deployment practices, and recovery procedures must all support the desired availability target.
Availability is an architectural decision, not a checkbox.

5. EC2 Pricing: Discount and Capacity Are Different Decisions
EC2 purchasing options suit different workload patterns:
- On-Demand: No long-term spending commitment. Useful for uncertain traffic, experiments, and short-term requirements; it is not an automatic capacity guarantee.
- Spot Instances: Discounted spare capacity that AWS can interrupt. Appropriate for workloads designed to restart, checkpoint, or tolerate interruption. Spot is not a customer bidding contest.
- Savings Plans: A one- or three-year commitment to eligible hourly compute spending. Compute Savings Plans can apply across eligible EC2, Fargate, and Lambda usage.
- Reserved Instances: One- or three-year billing commitments for matching EC2 usage. Regional RIs provide a discount without reserving capacity in a particular AZ; qualifying Zonal RIs can also reserve capacity.
- Dedicated Hosts: Physical servers dedicated to one account, relevant for certain licensing and compliance requirements.
If an application needs capacity assurance, On-Demand Capacity Reservations are another mechanism to evaluate. They are different from discount commitments.
The larger lesson: purchasing at a lower rate cannot fix an architecture that keeps unnecessary infrastructure running. First choose the execution model; then optimize how you purchase it.
6. Containers: Package the Application, Not the Whole Machine
A virtual machine includes its own guest operating system. A container packages application code with user-space dependencies while sharing the host OS kernel. On Linux, container isolation commonly uses namespaces and cgroups to separate processes and control resources.
This makes containers comparatively lightweight and helps teams deploy the same application artifact from development through production. Docker and other OCI-compatible tools are commonly used to build and run container images.
But portable does not mean guaranteed identical behavior. An
arm64 image may not run on an x86_64 host without the right build. Missing environment variables, secrets, permissions, network routes, external dependencies, and kernel differences can still break deployments.Containers simplify packaging. They do not independently deliver scaling, resilience, observability, or secure configuration. That is why container orchestration matters.

7. ECS vs EKS: Orchestration Is Not Compute
One running container is manageable. Hundreds of containers raise different questions: Where should a replacement start? How are deployments rolled out? Which capacity can accept the workload? How are failures detected and traffic routed?
Amazon Elastic Container Service (ECS) is AWS-native container orchestration. A task definition specifies container images and resource settings. ECS then schedules tasks and manages services, deployments, and scaling in conjunction with other AWS services.
When ECS runs on customer-managed EC2 capacity, registered EC2 hosts are called container instances. The ECS Container Agent, commonly supplied with ECS-optimized AMIs, runs on those hosts and communicates with ECS about the instances and tasks. You remain responsible for the EC2 fleet's operating system and capacity management.
Amazon Elastic Kubernetes Service (EKS) supplies a managed Kubernetes control plane. Kubernetes schedules workloads using constructs such as pods and deployments. EKS is useful when teams need Kubernetes APIs, ecosystem tools, or consistency with an existing Kubernetes platform. It can also introduce platform complexity for teams that do not otherwise need Kubernetes.
Both services coordinate workloads; neither is the entire underlying compute fleet. With supported configurations, containers can run on EC2, Fargate, or newer managed-capacity options.
Choose the orchestrator based on the platform requirement. Choose the compute capacity based on control, operational effort, and workload needs.

8. AWS Fargate: Containers Without Managing the Host Fleet
Even with container orchestration, running workloads on EC2 generally means provisioning host capacity, patching the guest OS, and maintaining the underlying fleet. AWS Fargate removes much of that host-management burden for supported ECS tasks and EKS pods.
A typical ECS-on-Fargate approach is to build a container image, store it in a registry such as Amazon ECR, define task requirements, and deploy the service using Fargate capacity. This describes the architecture not a tested walkthrough.
You still configure application behavior, networking, IAM permissions, images, logging, scaling policies, and deployment safeguards. Fargate does not make poorly configured applications safe or reliable by itself.
Its billing model is also important. Fargate charges for allocated vCPU, memory, and applicable extra storage over a task or pod's running period. A containerized API running continuously is billable even at 3 AM when it has no requests. A batch task that terminates after processing generally has a shorter billable lifetime. For ECS, Fargate Spot may be useful for interruption-tolerant workloads; availability and support depend on the capacity model.
Fargate reduces server administration. It does not mean every idle container costs zero.
9. AWS Lambda: Run Code in Response to Events
Consider an employee directory that lets users upload photographs. A background process must resize each image but only when an upload occurs. Maintaining a continuously running EC2 server solely to wait for occasional uploads may be unnecessary.
AWS Lambda executes functions in response to events without requiring you to provision a conventional application server. A typical design is:
- A user uploads an image under an S3
input/prefix.
- An S3 object-created event invokes a Lambda function.
- The function reads the image, creates a thumbnail, and writes to
output/.
- The application reads the processed image when needed.

Filtering matters: if a function writes an object into the same bucket that triggers it, and the new object matches the trigger, it can invoke itself repeatedly. An appropriate input-prefix filter or separate output bucket helps prevent that loop.
Six Lambda concepts worth knowing
- Function: The unit of code and configuration that Lambda runs.
- Trigger: A configured connection that causes invocation, directly or through an event source mapping.
- Event: The information delivered to the function, commonly as structured JSON data.
- Runtime: The execution environment for supported code languages or a custom runtime.
- Handler: The entry point invoked to process an event.
- Deployment package: The code and dependencies, commonly delivered as a ZIP archive or compatible container image.
These concepts explain the execution model without requiring a deployment tutorial or sample IAM policy.
For standard on-demand Lambda, charges generally depend on requests and compute duration, with other charges possible for configurations and related services. Provisioned Concurrency adds charges for configured warm capacity even when requests are not arriving.
Most Lambda functions have a 15-minute maximum invocation timeout. An important 2026 exception: eligible Lambda Managed Instances support up to 90 minutes for certain asynchronous and event-source invocations; synchronous invocations and some event sources retain shorter limits. The exact execution model matters.
Lambda still requires appropriate access controls, error handling, monitoring, and consideration of concurrency, downstream dependencies, and application behavior.
When a workload is naturally event-driven, ask whether a permanently running server is necessary.
10. Serverless and the AWS Shared Responsibility Model
Serverless does not mean there are no servers. It means the infrastructure layer is managed differently.
The AWS Shared Responsibility Model distinguishes security of the cloud, managed by AWS, from security in the cloud, which depends on how customers configure and use AWS services.
With EC2, AWS manages physical infrastructure while you manage the guest operating system, application software, IAM configuration, and network rules. With Fargate, AWS also manages the underlying container hosts, but you remain responsible for your application images, permissions, and workload configuration. With Lambda, AWS manages the function execution infrastructure while you remain responsible for code, data protection, access rights, and operational settings.
The division changes; responsibility never disappears.
Question | EC2 | ECS/EKS on Fargate | Standard on-demand Lambda |
|---|---|---|---|
Main execution unit | Virtual machine | Container task or pod | Function invocation |
Manage guest OS/host fleet? | Yes | No underlying host fleet | No underlying host fleet |
Manage application and permissions? | Yes | Yes | Yes |
Typical compute billing | Instance usage | Allocated running-task/pod resources | Requests and function duration |
Quiet periods | Running instances remain billable | Running tasks/pods remain billable | No invocation-duration charge without invocations |
This table simplifies service-specific exceptions and excludes related costs such as storage, networking, and provisioned capacity. Serverless is an operational model, not a promise that every bill reaches zero when requests stop.
11. Which Service Should You Choose? Start With the Workload
Requirement | Strong starting point | Reason |
|---|---|---|
Full OS and server-level control | EC2 | Guest OS and infrastructure flexibility |
AWS-native container scheduling | ECS | Task/service orchestration |
Kubernetes ecosystem or APIs | EKS | Managed Kubernetes control plane |
Containers without EC2 host administration | Fargate with ECS/EKS | Managed container compute |
Short, intermittent event processing | Lambda | Event-driven execution |
These are starting points, not guarantees. Real decisions also depend on latency, execution duration, architecture, network isolation, data persistence, licensing, engineering skills, and the full operating cost.
Scenario A: A quarterly spreadsheet upload
An inventory team uploads a file to S3 once every three months. Code parses its rows and updates a database. Lambda is a strong starting option when the file size, processing time, permissions, and database behavior fit the selected execution model. A 24/7 server dedicated only to waiting for the upload would generally be hard to justify.
Scenario B: A legacy Linux application
A company wants to move an existing Linux application to AWS with minimal refactoring. EC2 is a strong starting option because its operating-system environment can resemble the existing deployment. Whether the application supports Auto Scaling or multiple AZs depends on how it manages sessions, storage, and other state.
Scenario C: A new microservices platform
A team wants independently deployable services and repeatable container packaging. ECS or EKS can orchestrate the containers. Fargate or EC2 is then a separate choice about the execution layer. ECS may be simpler for AWS-focused teams; EKS makes sense when Kubernetes requirements justify its added concepts.

12. Planning an EC2 Application: The Decisions Beyond “Launch”
Suppose a team needs an employee directory web application. Before deployment, the architecture should answer these questions:
- Operating system and image: Which supported AMI and software dependencies are compatible with the application?
- Instance sizing: Which CPU, memory, processor architecture, and storage profile are appropriate?
- Networking: Should instances be private behind a load balancer? Which ports and routes are actually required?
- Identity and access: Which least-privilege IAM role and temporary credentials does the application need?
- Persistence: Which data must outlive instance replacement, stopping, or termination?
- Availability: Are multiple AZs, health checks, Auto Scaling, and resilient downstream data services necessary?
- Operations: How will CloudWatch metrics, logs, backups, patching, recovery, and cost visibility be handled?
CloudWatch supplies EC2 infrastructure metrics such as CPU and network activity. Guest OS measurements, including detailed memory utilization, generally require additional collection such as the CloudWatch agent.
This is intentionally an architecture checklist, not a claimed deployment, validated script, or hands-on benchmark. Launching an instance is not the same as operating a reliable application.
13. Five Principles to Remember
1. Control creates responsibility. EC2 offers flexibility, but you also manage more of the software environment.
2. Packaging, orchestration, and compute are separate choices. Containers package code; ECS/EKS coordinate workloads; EC2/Fargate provide supported execution capacity.
3. Serverless reduces infrastructure management, not the need for engineering. Security, observability, correctness, and cost controls still matter.
4. Architecture drives spending. Discounts do not compensate for idle capacity that should never have been provisioned.
5. Availability must be designed. Healthy servers alone do not guarantee a resilient application or data layer.
Quick knowledge check
Does an EC2 instance type identify the operating system? No. Instance type describes the compute resource profile; the AMI defines the starting operating-system environment.
Does Fargate automatically become free when an API has no traffic? No. Running Fargate tasks remain billable according to their allocated resources.
Final Thoughts: Choose the Problem First. Then Choose the Compute.
Use EC2 when control over a virtual server matters. Use ECS or EKS when container orchestration is justified. Consider Fargate when the workload fits containers and you want less host administration. Consider Lambda when execution is driven by events and the function model fits the workload.
No service is universally better. Each represents a different balance of control, convenience, cost, portability, and operational responsibility.
Ask what the application needs, how often it runs, how it recovers, which layers your team must maintain, and what the complete operating model will cost.
The goal of cloud engineering isn't to use the most AWS services. It's to build reliable systems with the least unnecessary complexity.
References and further reading
Series: Skill Builder Digital Classroom - AWS Cloud Technical Essentials (11 articles)
- …
- 3AWS Compute Explained: EC2 vs ECS vs EKS vs Fargate vs Lambda Which Should You Actually Use? This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article