2.2.2. Basic Container Deployment (ECS, Fargate)
First Principle: Basic container deployment enables developers to run packaged applications consistently, leveraging container orchestration to manage runtime environments and simplify scaling.
Once you have your Docker container image in Amazon ECR, you need a way to deploy and run it on AWS. Amazon ECS (Elastic Container Service) is AWS's native container orchestration service, and AWS Fargate provides a serverless compute option for running containers.
- Amazon ECS: (A fully managed container orchestration service that makes it easy to run, stop, and manage Docker containers on a cluster.) You define a Task Definition (a blueprint for your application specifying containers, CPU, memory, networking, and IAM role). Then, you create an ECS Service that maintains the desired number of tasks (running instances of your Task Definition).
- AWS Fargate: (A serverless compute engine for containers that works with both ECS and EKS.) With Fargate, you no longer need to provision, configure, or scale clusters of virtual machines. You simply define your Task Definition, and Fargate handles the underlying compute infrastructure.
- ECS Task: A running instance of a Task Definition on ECS.
Scenario: You've packaged your application as a Docker container image and pushed it to Amazon ECR. You need to deploy it to a scalable environment on AWS, and you prefer to minimize the operational burden of managing servers.
Lambda vs. Fargate Decision Guide
| Factor | Lambda | Fargate (ECS) |
|---|---|---|
| Execution model | Function per event | Long-running container |
| Max duration | 15 minutes | No limit |
| Scaling | Per-invocation, instant | Task-level, seconds |
| Packaging | Zip or container image | Container image only |
| State | Stateless (ephemeral /tmp) | Stateful within task lifetime |
| Pricing | Per ms + per request | Per vCPU/hour + memory/hour |
| Best for | Event-driven, short tasks | Web servers, long processes, microservices |
ā ļø Exam Trap: Fargate is serverless containers ā you don't manage EC2 instances. ECS with EC2 launch type gives you control over the underlying instances. Questions about "reducing operational overhead" for containers point to Fargate.
