Lesson 29

Serverless and Containers

AWS Lambda, Amazon ECS, Amazon EKS, AWS Fargate, and AWS Elastic Beanstalk

1. Containers on AWS

What is a Container?

Containers are a method of operating system virtualization. They package an application's code, configurations, and dependencies into a single object. Unlike virtual machines, containers do not contain a full guest operating system. They share the host OS kernel and run as resource-isolated processes.

Containers vs. Virtual Machines: VMs run on a hypervisor with a full guest OS per instance. Containers run on a shared OS kernel via a container engine (such as Docker). Containers are smaller and faster to start.

Docker is the software platform that packages software into containers. You create a container from an image, which is a template that holds everything the software needs to run: libraries, system tools, code, and runtime.

Amazon Elastic Container Service (Amazon ECS)

Amazon ECS is a highly scalable container management service that supports Docker containers. It orchestrates the running of containers on a cluster and maintains the fleet of nodes that run them.

To run an application on ECS, you create a task definition. This text file describes one or more containers (up to ten) that form your application. It specifies which container image to use, which ports to open, and what data volumes to mount. A task is the instantiation of a task definition within a cluster.

ECS Launch Types:
  • EC2 launch type — You manage the EC2 instances in the cluster. Provides granular control over instance type, networking, and scaling.
  • Fargate launch type — AWS manages the cluster infrastructure. You only package your application, specify CPU and memory, and launch. No servers to provision or scale.

Amazon Elastic Kubernetes Service (Amazon EKS)

Amazon EKS is a managed Kubernetes service. Kubernetes is open source software for container orchestration that deploys and manages containerized applications at scale.

EKS makes it easy to run Kubernetes on AWS without installing or maintaining your own Kubernetes control plane. It is certified Kubernetes conformant, so applications that run on upstream Kubernetes are compatible with EKS. EKS automatically manages the availability and scalability of cluster nodes, detects unhealthy control plane nodes, and replaces them.

ECS vs. EKS: Both orchestrate Docker containers. Use ECS if you want AWS-native orchestration. Use EKS if you need Kubernetes compatibility, open source tooling, or a multi-cloud strategy.

Amazon Elastic Container Registry (Amazon ECR)

Amazon ECR is a fully managed Docker container registry. It makes it easy to store, manage, and deploy Docker container images. ECR is integrated with both ECS and EKS. Images are encrypted at rest.

2. Serverless with AWS Lambda

AWS Lambda is an event-driven, serverless compute service. You upload your code as a Lambda function and set it to run on a schedule or in response to an event. Your code runs only when triggered. You pay only for the compute time you consume.

Lambda Benefits:
  • No server provisioning or management
  • Built-in fault tolerance across multiple Availability Zones
  • Automatic scaling from a few requests per day to thousands per second
  • Pay per request and per 100 milliseconds of compute time
  • Supports multiple languages: Python, Node.js, Java, C#, Go, Ruby, PowerShell

Lambda Event Sources

Lambda functions are triggered by event sources. Common event sources include:

  • Amazon S3 (object created, object deleted)
  • Amazon DynamoDB (table updates)
  • Amazon SNS (notifications)
  • Amazon SQS (messages in a queue)
  • Amazon API Gateway (HTTP requests)
  • Application Load Balancer (HTTP/HTTPS requests)
  • Amazon CloudWatch Events (scheduled or event-based triggers)

Lambda automatically monitors functions through Amazon CloudWatch and stores logs in CloudWatch Logs.

Lambda Limits

LimitValue
Maximum execution time (timeout)15 minutes
Maximum memory allocation10,240 MB
Concurrent executions per Region (soft limit)1,000
Deployment package size (unzipped)250 MB

Lambda Use Case Examples

Two classic Lambda patterns appear frequently on the exam:

Schedule-Based: Start and Stop EC2 Instances

A CloudWatch Event is scheduled to trigger a Lambda function at a specific time. The function uses an IAM role with permissions to stop (or start) EC2 instances. Common pattern: stop dev/test instances at night, restart them in the morning — reducing runtime costs by up to 65%.

  1. CloudWatch Event schedule triggers at 10 PM.
  2. Lambda function runs with an IAM role that allows ec2:StopInstances.
  3. EC2 instances enter the stopped state (no compute charges).
  4. A second CloudWatch Event at 7 AM triggers a Lambda function with ec2:StartInstances.

Event-Based: Create Thumbnail Images

Amazon S3 detects an object upload and invokes a Lambda function. The function reads the uploaded image, creates a thumbnail using graphics libraries, and saves it to a target S3 bucket. No servers to manage; you pay only when an upload triggers the function.

  1. User uploads an image to the source S3 bucket.
  2. S3 detects the object-created event and invokes Lambda, passing the bucket name and object key.
  3. Lambda assumes its execution role, reads the object, generates a thumbnail, and writes it to the target bucket.

3. Platform as a Service: AWS Elastic Beanstalk

AWS Elastic Beanstalk is a platform as a service (PaaS) that facilitates the quick deployment, scaling, and management of web applications. You upload your code, and Elastic Beanstalk automatically handles deployment, capacity provisioning, load balancing, automatic scaling, and health monitoring.

Elastic Beanstalk Key Facts:
  • Supports Java, .NET, PHP, Node.js, Python, Ruby, Go, and Docker
  • No additional charge for Elastic Beanstalk itself; you pay only for the underlying AWS resources
  • You retain full control over the AWS resources that power your application
  • Ideal when you want to focus on code, not infrastructure

4. Decision Guide

Use CaseServiceWhy
Run code in response to events, pay per executionAWS LambdaNo servers to manage; millisecond billing
Run Docker containers with AWS managing the clusterAmazon ECS with FargateNo EC2 instances to provision or scale
Run Docker containers with full control over the hostsAmazon ECS with EC2Granular control over instance type and networking
Use Kubernetes on AWS without managing the control planeAmazon EKSManaged Kubernetes, certified conformant
Deploy a web app quickly without managing infrastructureAWS Elastic BeanstalkPaaS with auto-deployment, scaling, and monitoring
Store and manage Docker imagesAmazon ECRFully managed registry integrated with ECS and EKS

Quiz: Serverless and Containers

Select one answer per question. You will receive immediate feedback.

1. A company wants to run Docker containers but does not want to manage the EC2 instances that run them. Which service and launch type should they use?
2. A developer needs to run a small Python script whenever a file is uploaded to S3. The script runs for less than 5 seconds. Which is the most cost-effective service?
3. Which AWS service is a fully managed Docker container registry that integrates with ECS and EKS?
4. A company uses Kubernetes on-premises and wants to migrate to AWS without changing their operational tooling. Which service should they use?
5. What is the maximum execution time (timeout) for a single AWS Lambda function invocation?
6. A startup wants to quickly deploy a web application without managing servers, load balancers, or scaling. They want to upload their code and have AWS handle the rest. Which service fits best?
7. Which statement accurately describes the difference between containers and virtual machines?
8. A company needs to orchestrate Docker containers and wants AWS to manage the control plane automatically. They also want Kubernetes compatibility. Which service should they choose?
9. A company wants to automatically stop their development EC2 instances every night at 10 PM and start them again at 7 AM to reduce costs. Which AWS services should they use together?
Progress: 0/9 correct (0%). Answer all questions to see the final recommendation.
Ask your teacher: Ask your agent about anything unclear: Lambda event sources, ECS task definitions, or when to choose Fargate over EC2.
Primary Source: AWS Academy Module 6: Compute.
Last updated: June, 2026© 2026 Shahriar Ahmed ShovonCredits