3.2 Lambda, Serverless Compute, and Container Services

Key Takeaways

  • Lambda runs code without provisioning servers, scales automatically, and charges per invocation and duration — ideal for event-driven architectures.
  • Lambda has a 15-minute maximum execution time, 10 GB memory limit, and 6 MB synchronous / 256 KB async payload limits.
  • ECS (Elastic Container Service) runs Docker containers on EC2 or Fargate; EKS (Elastic Kubernetes Service) runs Kubernetes on EC2 or Fargate.
  • Fargate is serverless compute for containers — you define CPU/memory, and AWS manages the underlying infrastructure.
  • Choose Lambda for short event-driven tasks, Fargate for containerized apps without server management, and ECS/EKS on EC2 for maximum container control.
Last updated: March 2026

Lambda, Serverless Compute, and Container Services

Quick Answer: Lambda = event-driven, <15 min, no servers. Fargate = serverless containers, no server management. ECS on EC2 = Docker containers with full control. EKS = Kubernetes on AWS. Choose based on execution duration, control needs, and operational overhead tolerance.

AWS Lambda

Lambda runs code in response to events without provisioning or managing servers.

Lambda Key Specs

FeatureLimit
Max execution time15 minutes (900 seconds)
Memory128 MB to 10,240 MB (10 GB)
vCPUsProportional to memory (1,769 MB = 1 vCPU)
Ephemeral storageUp to 10 GB (/tmp)
Concurrent executions1,000 per Region (soft limit, can be increased)
Deployment package50 MB zipped, 250 MB unzipped, 10 GB with container image
Sync payload6 MB
Async payload256 KB
Environment variables4 KB total

Lambda Event Sources

SourceInvocation TypeExample
API GatewaySynchronousREST API endpoint
S3AsynchronousObject uploaded/deleted
SQSPollingProcess queue messages
DynamoDB StreamsPollingReact to table changes
EventBridgeAsynchronousScheduled tasks, event rules
SNSAsynchronousPub/sub notifications
CloudWatch LogsAsynchronousLog processing
KinesisPollingStream processing
ALBSynchronousHTTP request handling

Lambda Best Practices

  • Keep functions small and focused (single responsibility)
  • Set appropriate timeout (don't use 15 min for a 3-second function)
  • Use environment variables for configuration
  • Store dependencies in Lambda Layers for reuse
  • Use Provisioned Concurrency to avoid cold starts for latency-sensitive functions
  • Use Reserved Concurrency to limit execution and prevent throttling of other functions

Lambda Pricing

  • Free tier: 1 million requests + 400,000 GB-seconds per month
  • Per request: $0.20 per million requests
  • Per duration: $0.0000166667 per GB-second

Amazon ECS (Elastic Container Service)

ECS is AWS's container orchestration service for running Docker containers.

ECS Launch Types

FeatureEC2 Launch TypeFargate Launch Type
InfrastructureYou manage EC2 instancesAWS manages infrastructure
ScalingYou manage Auto Scaling of EC2Automatic
PricingEC2 instance pricingPer vCPU + memory per second
ControlFull access to hostNo access to host
GPU supportYesLimited
Best forFull control, GPU, large clustersSimplicity, less operational overhead

ECS Key Concepts

ConceptDescription
Task DefinitionBlueprint for containers (image, CPU, memory, ports, env vars)
TaskRunning instance of a Task Definition
ServiceMaintains desired count of tasks, integrates with ELB
ClusterLogical grouping of tasks/services

Amazon EKS (Elastic Kubernetes Service)

EKS runs Kubernetes on AWS without installing or operating your own Kubernetes control plane.

FeatureDetail
Control planeAWS managed (multi-AZ, patched, upgraded)
Worker nodesEC2 instances, Fargate, or both
CompatibilityStandard Kubernetes — all existing K8s tools work
Use caseOrganizations already using Kubernetes

AWS Fargate

Fargate is serverless compute for ECS and EKS — you specify CPU and memory, and AWS manages everything else.

FeatureDetail
No serversNo EC2 instances to manage
PricingPer vCPU and memory per second
ScalingAutomatic based on task count
SecurityTask-level isolation (each task runs in its own kernel)
Best forMicroservices, batch processing, web applications

Choosing the Right Compute Service

ScenarioBest Service
Event-driven, <15 min executionLambda
Containerized app, minimal opsECS or EKS on Fargate
Containerized app, full control neededECS or EKS on EC2
Long-running stateful applicationsEC2
Batch processing (large scale)AWS Batch (uses EC2 or Fargate)
GPU-intensive ML trainingEC2 (P-series) or SageMaker

On the Exam: "Least operational overhead for running containers" → Fargate. "Run code in response to S3 uploads" → Lambda. "Organization uses Kubernetes and wants to migrate to AWS" → EKS.

Test Your Knowledge

A company wants to run Docker containers without managing any servers or infrastructure. Which service should they use?

A
B
C
D
Test Your Knowledge

What is the maximum execution time for an AWS Lambda function?

A
B
C
D
Test Your Knowledge

A company is migrating an existing Kubernetes application to AWS. They want to use their existing Kubernetes tools and configurations. Which service should they use?

A
B
C
D