Modernizing Applications with Serverless and Containers. It's the difference between owning a massive truck to move a single sofa versus calling a taxi for each trip — you stop paying for what you don't use. For the SAP-C02 exam, this topic is about knowing which AWS tools to pick when your company wants to stop babysitting servers and start focusing on code that actually makes money.
Jump to a section
A simple way to picture Modernizing Applications with Serverless and Containers
Have you ever wondered how a busy restaurant kitchen handles a dinner rush without collapsing into chaos?
The old way of running a kitchen was like managing a traditional IT server. You had one giant stove (your on-premises server). Every dish (application) had to be cooked on that same stove. If you needed more capacity for a Friday night rush, you had to buy a whole new stove (provision a new server) — even if you only needed it for a few hours. The stove sat idle on Monday and Tuesday, costing you money. If the stove broke (server failure), the entire kitchen shut down until a repair person (your IT team) fixed it. This is the monolithic, server-based world that SAP-C02 asks you to modernise.
Now imagine a modern kitchen. Instead of one giant stove, you have a fleet of small, portable induction hobs (containers). Each hob cooks only one specific dish. When you need to make more pasta, you grab another hob from a stack (container image registry), plug it in, and it starts cooking instantly. You don't need to care where the electricity comes from; you just trust it's there. That electricity is the 'serverless' part — you don't manage the power grid, you just use it when you need it. At the end of the night, you unplug the extra hobs and they vanish. You only paid for the electricity they used (pay-per-use pricing). This is application modernisation: breaking your giant application into small, independent pieces (containers) and running them without managing servers (serverless).
Imagine you run a small e-commerce website that sells custom T-shirts. Five years ago, you would have bought a physical computer server, installed an operating system (like Linux), set up a database, and installed your T-shirt shop application on that one machine. That machine was your 'server'. It ran 24/7, even at 3 AM when nobody was buying T-shirts. You paid electricity bills, you worried about the hard drive crashing, and if you ran a big advertising campaign, you had to buy a second server because the first one couldn't handle the extra customers. That's the old way, and AWS calls it 'undifferentiated heavy lifting' — work that doesn't make your T-shirt shop unique.
Modernising applications means moving away from that model. Instead of managing physical servers, you use two key AWS approaches: containers and serverless. Let us break them down.
Containers are like shipping containers for your code. In the old days, you would pack your application (the code, the settings, the libraries it needs) directly onto the server. If you wanted to move it to a different server, you had to unpack everything and hope it worked the same way. Containers solve this. A container is a lightweight, standalone package that includes your application code plus everything it needs to run — the runtime (like Python or Node.js), the system tools, libraries, all of it. You build this package once, called a 'container image', and you can run it on any machine that has a container engine (like Docker). This means your application behaves identically on your laptop, on a test server, and on AWS. The exam focuses on AWS services like Amazon Elastic Container Service (ECS) and Amazon Elastic Kubernetes Service (EKS). ECS is AWS's own container orchestrator — a tool that automatically starts, stops, and manages your containers across a cluster of virtual machines. EKS does the same job but uses the industry-standard Kubernetes system, which is popular if your company wants to avoid being locked into AWS-only tools.
Serverless is a step further. With serverless, you do not manage any servers at all. You simply upload your code and tell AWS, 'Run this when someone visits my website.' AWS automatically spins up the compute power needed, runs your code, and then shuts it down when it is done. You pay only for the time your code actually runs. The primary service for this is AWS Lambda. Lambda runs short pieces of code (functions) in response to events — like an HTTP request from a user, a file being uploaded to S3, or a message arriving in a queue. AWS handles everything: the operating system, the runtime updates, the scaling, the availability. Lambda functions have a maximum execution time of 15 minutes and are best for stateless tasks — meaning they do not remember anything from one run to the next; all state must be stored elsewhere, like in a database (DynamoDB) or a key-value store (ElastiCache).
Why modernise? Three reasons: cost, agility, and reliability. Cost: you stop paying for idle servers. Agility: you can deploy new features in minutes instead of days. Reliability: if one container or Lambda function fails, AWS automatically starts a new one — your application stays up. The SAP-C02 exam tests your ability to design architectures that combine these services. For example, you might use API Gateway (a managed service for creating REST APIs) to accept web requests, then route them to a Lambda function that processes the request and stores data in DynamoDB. This is called a 'serverless architecture'. Or you might run a containerised microservice — one small part of your application — on ECS, and have it communicate with other microservices via Amazon SQS (a message queue) or Amazon SNS (a notification service).
The key difference to remember for the exam: containers still run on virtual machines (even if you do not see them). You are responsible for patching the container's OS if you use a custom image. Serverless (Lambda) completely abstracts the underlying infrastructure — you never touch the OS. Containers are better for long-running, stateful applications. Serverless is better for event-driven, short-lived tasks. The exam will ask you to choose between them based on requirements like 'requires a persistent connection' (go containers) or 'needs to scale to zero when idle' (go serverless).
Analyse the Legacy Monolith
Identify the different business capabilities within the existing application (user management, billing, notifications). This step determines which parts can be extracted into separate services. For the exam, always look for 'independent components' that can run in isolation.
Choose the Compute Model
Decide between containers and serverless for each component. If the component is event-driven and runs under 15 minutes, choose Lambda. If it requires a persistent connection or long execution time, choose ECS/Fargate or EKS. This decision is critical for exam questions about cost and performance.
Containerise or Package Code
For containers, create a Dockerfile and build an image, pushing it to Amazon ECR. For Lambda, zip your code and dependencies or use a deployment package. The exam may test your knowledge of Lambda deployment limits: 250 MB zipped, 250 MB unzipped, 50 MB for direct upload to the console.
Set Up Event Sources and Triggers
Connect your new services to the events that drive them. For example, attach an API Gateway trigger to a Lambda function for web requests, or configure an S3 bucket event to invoke Lambda when a new object is uploaded. The exam tests which AWS services can directly invoke Lambda (S3, SQS, SNS, DynamoDB Streams, API Gateway, CloudWatch Events, Kinesis).
Implement Orchestration and Auto Scaling
If using containers, define a task definition in ECS or a pod in EKS, and set up auto scaling policies based on CPU, memory, or custom metrics. For Lambda, concurrency limits and reserved concurrency are the equivalent controls. The exam emphasises configuring auto scaling for containers and understanding Lambda's default concurrency limit of 1,000 per account.
Configure Monitoring and Logging
Use Amazon CloudWatch to collect logs from containers and Lambda functions. Set up CloudWatch dashboards and alarms for error rates, latency, and resource usage. The exam may ask about integrating X-Ray for tracing requests across microservices.
An IT professional tasked with modernising their company's legacy application would follow a structured process. Let us say the company is a logistics firm with a monolithic application that tracks package deliveries. The old system runs on a single physical server in their office, and it keeps crashing during peak holiday seasons. Their boss tells them, 'Make it handle 10x the traffic, and do not buy any new hardware.'
The first step is to break the monolith into smaller pieces. The professional analyses the application and identifies distinct components: the user login function, the package tracking map, the customer notification service, and the billing module. These become candidate pieces to run as separate containers or Lambda functions.
Next, they decide on the hosting strategy. For the billing module (which needs a persistent database connection and can run for minutes at a time), they choose containers on Amazon ECS with AWS Fargate. Fargate is a 'serverless compute engine for containers' — it means they do not manage the underlying servers; AWS handles the virtual machines. For the notification service (which fires every time a package is scanned and runs in under a second), they choose AWS Lambda. For the login function, they use Amazon Cognito (a managed identity service) combined with Lambda to verify users.
The practical steps the IT pro takes include:
Containerising the billing module: writing a Dockerfile that packages the Python billing code and its dependencies, then storing the container image in Amazon Elastic Container Registry (ECR).
Setting up a continuous integration/continuous deployment (CI/CD) pipeline using AWS CodePipeline and CodeBuild. Every time they push code to a GitHub repository, the pipeline automatically builds a new container image and deploys it to a test environment on ECS.
Writing the notification Lambda function in Node.js, configured to trigger from an Amazon SQS queue. When a package scan event lands in the queue, Lambda processes it and sends an SMS via Amazon SNS.
Configuring Auto Scaling: for the containers on ECS, they set minimum 2 and maximum 20 tasks. For Lambda, scaling is automatic by default — no configuration needed.
Finally, they monitor everything. They use Amazon CloudWatch to collect logs and metrics. If the billing container's CPU usage exceeds 80%, CloudWatch triggers a scaling policy that spins up more containers. If a Lambda function throws an error, CloudWatch creates an alarm and sends a message to the operations team via Amazon Simple Notification Service (SNS).
The result: the company now runs on a modern, resilient system. During a peak sale, the number of running containers and Lambda invocations automatically grows to meet demand. When the sale ends, everything scales back down. The IT team no longer wakes up at 3 AM to reboot a server. The exam tests whether the candidate can design this exact flow, choosing the right AWS services and explaining why they are appropriate.
The SAP-C02 exam dedicates a significant portion of Domain 4 (Design for New Solutions) to this topic. You will see it tested in three major ways: scenario-based multiple-choice questions, multi-select questions asking for the 'most cost-effective' or 'most resilient' combination of services, and occasionally a question that asks you to identify the 'anti-pattern' — the design that looks right but is wrong for modernisation.
The exam loves to test the distinction between AWS services that manage containers and those that are truly serverless. For example, a question might describe an application that needs to process real-time stock market data. The answer choices might include Amazon ECS (with EC2, which means you manage servers), Amazon ECS (with Fargate, serverless compute), and AWS Lambda. The correct answer is often Lambda if the processing is stateless and short-lived, but ECS with Fargate if the processing requires more than 15 minutes, uses custom libraries that exceed the Lambda deployment package limit (250 MB zipped, 250 MB unzipped), or requires a persistent network connection.
Key concepts the exam tests frequently:
Lambda execution limits: 128 MB to 10,240 MB memory, 15-minute timeout, 512 MB /tmp storage, 1,000 concurrent executions per account soft limit.
Container orchestrator differences: ECS is simpler and tightly integrated with AWS; EKS offers portability but more complexity.
Event sources for Lambda: S3, DynamoDB Streams, SQS, SNS, API Gateway, CloudWatch Events, Kinesis. The exam expects you to know which service is best for which trigger.
The 'strangler fig pattern': a modernisation strategy where you gradually replace pieces of a monolith with microservices or Lambda functions instead of rewriting the entire system at once.
AWS App Runner versus AWS Fargate: App Runner is simpler (just point to your code or container), Fargate gives you more control.
Common traps: - 'Lambda can be used for long-running processes' is always wrong; maximum 15 minutes. - 'Containers are inherently serverless' is wrong; only if you run them on Fargate. Running containers on EC2 means you manage the virtual machines. - 'You should use a serverless architecture for everything' is a trap; stateful applications with long-lived connections (like WebSocket games) are better suited to containers. - 'API Gateway is the only way to trigger Lambda via HTTP' is wrong; you can also use Application Load Balancer (ALB) or the Function URL feature.
Memorise this decision framework: if the application runs less than 15 minutes and is event-driven, use Lambda. If it runs longer, needs a specific OS, or uses a large package, use containers (ECS/Fargate). If you need to move existing Docker containers to AWS with minimal changes, use ECS or EKS. If you want to completely avoid managing anything except code, use Lambda. The exam will give you a scenario with specific constraints — always map them to this framework.
Serverless (AWS Lambda) is best for event-driven, short-lived tasks under 15 minutes where you want zero infrastructure management.
Containers (ECS, EKS, Fargate) are best for long-running applications, stateful services, or when you need a specific runtime environment not supported by Lambda.
AWS Fargate is the 'serverless' option for containers — you do not manage the underlying EC2 instances.
The strangler fig pattern is the recommended approach for modernising a monolith: gradually replace pieces with microservices or serverless functions.
API Gateway combined with Lambda is a standard pattern for building serverless REST APIs that scale automatically.
Lambda functions are stateless by design; use DynamoDB, S3, or ElastiCache to persist state between invocations.
These come up on the exam all the time. Here's how to tell them apart.
AWS Lambda
Maximum execution time of 15 minutes
Stateless by design; no persistent connections
Priced per invocation and duration (ms)
Amazon ECS (Fargate)
Can run indefinitely (long-running tasks)
Can maintain persistent network connections
Priced per second of vCPU and memory allocated
Amazon ECS
AWS-native, simpler configuration
No separate control plane cost
Deep integration with other AWS services (IAM, VPC)
Amazon EKS
Industry-standard Kubernetes API
Separate control plane cost (about $0.10/hour)
Portable across AWS, Azure, and on-premises
Container (Docker)
Shares host OS kernel
Starts in milliseconds
Smaller disk and memory footprint
Virtual Machine (EC2)
Full guest OS per VM
Starts in minutes
Larger disk and memory footprint
Serverless Architecture
Zero server management
Auto-scales to zero when idle
Best for bursty, event-driven workloads
Microservices on Containers
You manage orchestration (or use Fargate)
Minimum number of running containers
Best for steady-state, long-running services
Mistake
Serverless means there are no servers at all, so my application runs on magic.
Correct
Serverless still runs on servers, but the cloud provider manages them. AWS owns the physical hardware and operating system; you only provide code. You never see or log into the server.
The name 'serverless' is misleading. Beginners think it literally means no compute hardware exists, but it just means the server is abstracted away from the developer.
Mistake
Containers and virtual machines are basically the same thing.
Correct
A virtual machine (VM) runs a full guest operating system on top of a hypervisor. A container runs a single application process in user space, sharing the host kernel. Containers start in milliseconds, VMs take minutes. Containers use less memory and disk space.
Both are used for isolation, so people conflate them. But the underlying architecture and performance characteristics are very different, and the exam tests this distinction.
Mistake
If I use Docker on my laptop, I am already using a container orchestration service.
Correct
Docker runs a single container. You need an orchestrator like ECS or EKS to manage multiple containers across multiple machines, handle networking, load balancing, auto-scaling, and rolling updates.
People confuse the container runtime (Docker) with the orchestrator. The exam expects you to know when Docker is insufficient and you need ECS or EKS.
Mistake
Amazon ECS and Amazon EKS are essentially the same thing with different names.
Correct
ECS is AWS's native container orchestrator. EKS is a managed Kubernetes service. ECS is simpler and cheaper (no control plane cost) but locks you into AWS. EKS is portable across clouds and on-premises but has a managed control plane cost.
Both launch containers, so they seem interchangeable. But the exam tests the trade-offs in vendor lock-in, cost, and team expertise.
Mistake
A Lambda function can connect to a database and keep the connection open forever.
Correct
Lambda functions are stateless and ephemeral. The database connection must be created each time the function runs or reused from an external connection pool. Lambda functions can stay 'warm' for a few minutes, but the connection will be dropped when the execution environment is recycled.
People think 'serverless' means persistent connections work the same as on a server. The exam treats this as a common mistake, especially with RDS Proxy.
Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.
A virtual machine runs a full guest operating system on virtualised hardware. A container runs a single application process, sharing the host machine's operating system kernel. Containers are much lighter and start faster, but they run only on the same OS type as the host (e.g., Linux containers on Linux hosts).
Yes, AWS Lambda supports container images as a deployment package option (since re:Invent 2020). You can package your Lambda function code and dependencies into a Docker container image up to 10 GB in size (before it was 250 MB). This makes it easier to use existing container tooling for serverless applications.
It is a modernisation strategy where you gradually replace pieces of a monolithic application with new microservices or serverless functions. The name comes from a fig tree that grows around a host tree, eventually replacing it. The exam tests this pattern as the safest way to modernise without a full rewrite.
Use ECS if you want a simpler, cheaper option deeply integrated with AWS services like IAM roles, CloudWatch, and VPC networking. Use EKS if your team already knows Kubernetes, you need portability across clouds, or you run third-party software that only supports Kubernetes.
Fargate is a compute engine for containers that lets you run containers without managing the underlying EC2 instances. You define your containers and their resource requirements, and AWS handles provisioning and scaling the servers. It is often called 'serverless containers'.
The maximum execution timeout for a single Lambda function invocation is 15 minutes (900 seconds). If your task takes longer, you must use a different service like ECS (with Fargate or EC2) or step functions that orchestrate multiple Lambda invocations.
You've finished Modernizing Applications with Serverless and Containers. Continue through the SAP-C02 study guide to build a complete picture of the exam.
Done with this chapter?