2.2. Developing with Containers on AWS
š” First Principle: Containers package your application with its dependencies into a portable unit ā unlike serverless, you control the runtime environment but take on more operational responsibility.
Why use containers when Lambda exists? Because some workloads need long-running processes, custom runtimes, or more than 15 minutes of execution time. Without containers, developers must re-architect applications that don't fit the serverless model. Consider a Java application with a 30-second startup time ā Lambda cold starts would destroy user experience, but ECS keeps the container warm and ready. The trade-off is clear: containers give you more control but require you to think about orchestration, scaling policies, and image management.
Think of Lambda as ordering a taxi (show up, ride, leave) versus containers as leasing a car (more flexibility, but you handle maintenance, parking, and fuel).
| Feature | Lambda | ECS/Fargate |
|---|---|---|
| Max duration | 15 minutes | Unlimited |
| Scaling | Automatic per-request | Task-based auto-scaling |
| Cold start | Yes (ms to seconds) | No (tasks stay running) |
| Pricing | Per-request + duration | Per-task hour |
| Best for | Event-driven, short tasks | Long-running, stateful apps |
