SkillSprout
Chapter 4 · Lesson 1
Beginner
5 min read

Compute: EC2, Containers and Lambda

Overview

Compute is the processing power that runs your programs. AWS offers several ways to get it, from full virtual servers you control to tiny functions that run only when triggered.

The easiest comparison is transport. Amazon EC2 is like renting a car: you choose the model and drive it yourself. Containers are like a taxi fleet service where vehicles are standardised. AWS Lambda is like a ride-hailing trip: you only pay for the journey and never think about the vehicle.

For the exam you must recognise what each compute service does, which ones are serverless, and how Auto Scaling and load balancing give applications elasticity and high availability.

Key Concepts

  • Amazon EC2 provides resizable virtual servers (instances) in the cloud, launched from an AMI (Amazon Machine Image).
  • EC2 instance families are optimised for different needs: general purpose, compute optimised, memory optimised, storage optimised and accelerated computing (GPU).
  • Auto Scaling automatically adds or removes EC2 instances based on demand; Elastic Load Balancing (ELB) distributes traffic across healthy targets in multiple AZs.
  • AWS Lambda runs code in response to events with no servers to manage; you pay per request and execution time (maximum 15 minutes per invocation).
  • Amazon ECS and Amazon EKS run containers (EKS uses Kubernetes); AWS Fargate removes the need to manage the underlying servers for either.
  • AWS Elastic Beanstalk deploys web applications by handling provisioning, load balancing and scaling for you.
  • Amazon Lightsail offers simple virtual servers with predictable pricing for small projects; AWS Batch runs batch computing jobs at scale.
  • EC2 purchasing options include On-Demand, Reserved Instances, Savings Plans, Spot Instances and Dedicated Hosts.

Detailed Notes

Amazon EC2 essentials

You pick an AMI (operating system + software), an instance type, networking and storage, then launch. You manage the guest OS and applications. Billing is per second for Linux (one-minute minimum) on most instance types.

Instance type families

FamilyOptimised forExample useExample type
General purposeBalancedWeb servers, small databasest3, m7i
Compute optimisedHigh CPUBatch, gaming, media encodingc7g
Memory optimisedLarge memoryIn-memory databases, analyticsr7g
Storage optimisedHigh disk I/ONoSQL, data warehousingi4i
Accelerated computingGPUs / chipsML training, graphicsp5, g5

EC2 purchasing options

OptionDiscountCommitmentBest for
On-DemandNoneNoneShort, unpredictable workloads
Savings PlansUp to ~72%1 or 3 years of spend ($/hour)Steady usage with flexibility
Reserved InstancesUp to ~72%1 or 3 years for a configurationSteady, predictable usage
Spot InstancesUp to ~90%None, can be interrupted with 2-minute noticeFault-tolerant, flexible jobs
Dedicated HostsVariesOptionalBring-your-own licences, compliance

Scaling and load balancing

Auto Scaling groups keep a desired number of healthy instances and add capacity when metrics (like CPU) rise. Elastic Load Balancing spreads requests; the common types are:

Load balancerLayerUse
Application Load Balancer (ALB)7 (HTTP/HTTPS)Web apps, path/host routing
Network Load Balancer (NLB)4 (TCP/UDP)Extreme performance, static IPs
Gateway Load Balancer3Third-party virtual appliances

Serverless and containers

ServiceWhat it isServers to manage?
LambdaEvent-driven functionsNone
FargateServerless compute engine for containersNone
ECSAWS-native container orchestrationEC2 or Fargate
EKSManaged KubernetesEC2 or Fargate
Elastic BeanstalkApplication deployment platformCreated for you

Launching an instance and a function

bash
aws ec2 run-instances --image-id ami-0abcdef1234567890 --instance-type t3.micro \
  --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=web-1}]'

aws lambda invoke --function-name resize-image --payload '{"key":"photo.jpg"}' out.json
OptionWhat it is
Dedicated InstancesInstances on hardware dedicated to your account (may share host with your other instances)
Dedicated HostsA whole physical server you control; supports BYOL by socket/core visibility
On-Demand Capacity ReservationsReserve capacity in a specific AZ for any duration, billed whether used or not
AWS Auto ScalingService that scales EC2, ECS, DynamoDB and Aurora resources via scaling plans

Choosing the right option

json
{
  "needOSControlOrLegacySoftware": "EC2",
  "shortEventDrivenTask": "Lambda",
  "packagedMicroservices": "ECS or EKS with Fargate",
  "justDeployMyWebApp": "Elastic Beanstalk",
  "simpleLowCostWebsite": "Lightsail"
}

Remember the shared responsibility split: on EC2 you patch the OS; with Lambda and Fargate AWS manages the underlying hosts.

Real World Example

A news website runs its web tier on EC2 instances in an Auto Scaling group behind an Application Load Balancer spread across two AZs, so traffic spikes during breaking news are absorbed automatically.

When an editor uploads an image, an S3 event triggers a Lambda function that creates thumbnails, costing fractions of a cent per image. Overnight analytics jobs run on Spot Instances because they can be re-run if interrupted, cutting compute cost by more than half.

Architecture Diagram

Elastic web tier with serverless helpers
Architecture
AWS Cloud
Visitors
Load balancer

Auto Scaling group

EC2 (AZ a)
EC2 (AZ b)
S3 bucket
Lambda
  1. 1Visitors reach the load balancer, which checks target health.
  2. 2Requests are spread across instances in multiple Availability Zones.
  3. 3Auto Scaling adds or removes instances as demand changes.
  4. 4Uploads to S3 trigger Lambda for event-driven processing without servers.

Best Practices

  • ✓Run instances across multiple AZs behind a load balancer for availability.
  • ✓Right-size instances using monitoring data and pick current-generation types.
  • ✓Use Spot for interruptible work and Savings Plans for steady baselines.
  • ✓Prefer Lambda or Fargate when you want to avoid server management.
  • ✓Use IAM roles for EC2, not embedded credentials, and patch AMIs regularly.

Common Interview Questions

Exam Tips

CLF-C02 focus

  • "Run code without managing servers" = Lambda.
  • "Containers without managing servers" = Fargate.
  • "Cheapest, can be interrupted" = Spot; "steady 1-3 year usage" = Reserved / Savings Plans.
  • "Deploy a web app without managing infrastructure details" = Elastic Beanstalk.

Finished this lesson?

0 of 43 lessons done · 0% of the course