AWS Containers & Serverless: Core Concepts
Container and serverless topics appear consistently on AWS exams. The key is understanding the differences between Lambda, ECS, and Fargate, and knowing which service to use in a given scenario. A solid grasp of Docker fundamentals will also serve you well.
---
What is Docker?
Docker is a platform that packages applications into containers so they run identically across any environment. It effectively solves the "works on my machine" problem that often arises between development and production environments.
Key Advantages of Docker
| Advantage | Description | |-----------|-------------| | Portability | Runs identically on any OS or machine | | Fast startup | Containers start in seconds | | Lightweight | Shares the host OS kernel, making it lighter than VMs | | Scalability | Scale up or down in seconds |
Docker vs Virtual Machines (VMs)
Both technologies serve similar purposes but differ in implementation. Docker shares the host OS kernel, making it significantly lighter and faster than traditional virtual machines.
| Category | Docker Container | Virtual Machine (VM) | |----------|-----------------|---------------------| | Size | Lightweight and fast (shared OS) | Heavy (includes full OS) | | Startup time | Seconds | Minutes | | Portability | Very high | Relatively low | | Best for | Microservices, modern apps | Multi-OS environments |
Docker Image Registries
Docker Hub (): Public image registry Amazon ECR (Elastic Container Registry): AWS's private container image registry
---
Container Execution Services: ECS vs Fargate
Amazon ECS (Elastic Container Service)
ECS is a fully managed container orchestration service that runs, stops, and manages Docker containers on AWS. It integrates with IAM, VPC, ELB, and ECR, and offers two launch modes.
| Mode | Description | |------|-------------| | EC2 Mode | You provision and manage EC2 instances directly | | Fargate Mode | Serverless — no need to manage EC2 instances |
AWS Fargate
Fargate is a serverless container execution engine. You do not need to provision or manage EC2 instances — you pay only for the vCPU and memory your container requires. It works with both ECS and EKS.
Key comparison points frequently tested on exams: ECS + EC2: You manage the underlying servers (EC2 instances) ECS + Fargate: Serverless — AWS manages the infrastructure automatically ECR: Where you store Docker images used by ECS/Fargate
---
What is Serverless?
Serverless does not mean there are no servers — it means you do not have to manage them. You deploy your code (functions), and AWS handles provisioning, scaling, and management. It is optimized for event-driven architectures. Representative services include Lambda, DynamoDB, S3, and Fargate.
---
AWS Lambda — The Serverless Core
Lambda is a FaaS (Function as a Service) offering that lets you run code without managing servers. It executes only when an event occurs, so you are billed only for the time your code actually runs.
EC2 vs Lambda Comparison
| Category | EC2 | Lambda | |----------|-----|--------| | Execution | Always-running virtual server | Runs only when triggered by events | | Scaling | Manual instance addition/removal | Automatic scaling | | Billing | Full running time | Only for time used | | Limits | RAM/CPU limits | Max execution time: 15 minutes |
Lambda Key Characteristics
Maximum execution time: 15 minutes (suited for short-lived functions) Free tier: 1 million requests + 400,000 GB-seconds per month Automatic scaling: from a few requests per day to thousands per second RAM: up to 10 GB (increasing RAM also improves CPU and network performance)
Supported Runtimes
Node.js, Python, Ruby, Java, Go, .NET Core, Custom Runtime
Common Lambda Use Cases
Automatically generate thumbnails when images are uploaded to S3 Schedule serverless cron jobs Build serverless REST APIs with API Gateway
Lambda Pricing
| Item | Free Tier | Additional Cost | |------|-----------|----------------| | Requests | 1 million per month | $0.20 per million | | Execution time | 400,000 GB-seconds per month | $1.00 per 600,000 GB-seconds |
Lambda is optimized for short-duration event processing (under 15 minutes) and is not well suited for long-running batch workloads.
---
Amazon API Gateway
API Gateway is a fully managed service that exposes Lambda functions as HTTP APIs. It supports REST, HTTP, and WebSocket APIs and scales in a serverless fashion. Security, authentication, throttling, and caching are all built in.
Combining Lambda with API Gateway gives you a fully serverless API architecture.
---
AWS Batch — Large-Scale Batch Processing
AWS Batch is a fully managed service for running large-scale batch workloads. It automatically provisions EC2 or Spot instances based on job requirements. Batch jobs are defined as Docker images and run on ECS. Common use cases include machine learning, rendering, and large-scale data processing.
Lambda vs AWS Batch Comparison
The most significant difference between the two is execution duration. Lambda is suited for tasks that complete within 15 minutes; AWS Batch handles longer workloads.
| Category | Lambda | AWS Batch | |----------|--------|-----------| | Architecture | Event-driven | Batch processing | | Execution time | Up to 15 minutes | Minutes to hours | | Infrastructure | Fully serverless | Uses EC2 / Fargate | | Disk | Limited (ephemeral) | EBS / Instance Store | | Best for | Short, lightweight functions | Large-scale, long-running compute |
---
Amazon Lightsail — All-in-One for Beginners
Lightsail provides virtual servers, storage, databases, and networking at a low, predictable price. It is a simplified alternative to EC2, RDS, ELB, EBS, and Route 53, and is designed for users with limited cloud experience.
It is commonly used for simple web applications such as WordPress, LAMP stacks, and Node.js apps, as well as development and test environments. Note that while Lightsail offers high availability, it does not support auto-scaling and has limited integration with other AWS services.
---
Service Comparison at a Glance
| Service | Key Keywords | Use Cases | |---------|-------------|----------| | Docker | Container, portability, fast startup | App packaging and deployment | | ECR | Docker image registry (private) | Image storage for ECS/Fargate | | ECS | Container orchestration | Run and manage Docker containers | | Fargate | Serverless containers | Run containers without EC2 | | Lambda | Serverless, FaaS, max 15 min | Short-lived event-driven functions | | API Gateway | Serverless API | Expose Lambda as HTTP API | | AWS Batch | Batch processing, long-running jobs | ML, rendering, large-scale ETL | | Lightsail | Low-cost, simple, beginner-friendly | WordPress, small web apps |
---
Pre-Exam Checklist
Docker = containers that run identically anywhere ECR = AWS's private Docker image registry ECS = Docker container orchestration (choose EC2 or Fargate) Fargate = serverless containers (no EC2 management) Lambda = serverless FaaS, maximum execution time 15 minutes Lambda free tier: 1 million requests per month at no cost Lambda + API Gateway = fully serverless API Batch jobs over 15 minutes → AWS Batch Lightsail = low-cost all-in-one for beginners (no auto-scaling)