Chapter 93: AWS Lambda and Serverless for DevOps
93.13 Lambda versus containers and EC2
Story (fictional teaching scenario). In a fictional Mumbai architecture review, Rahul and Emma from Bristol choose different compute models for different jobs instead of forcing everything into Lambda.
Why
One service is not best for every duration, protocol, traffic pattern or operational need.
What
- EC2 gives you a virtual machine: OS patching and capacity are your responsibility.
- ECS runs container tasks/services on AWS; Fargate reduces host management (chapter 89).
- Lambda runs event handlers with a runtime and invocation model, within its configured limits.
- Container packaging for Lambda still follows Lambda invocation and scaling rules; it does not turn Lambda into an ECS service.
How
-
List duration and event shape.
-
List runtime, network and control requirements.
-
Compare measured total cost and operational effort.
Example 1: Choose by workload
- Read the input and the code.
Thumbnail after upload -> Lambda candidate
Always-running worker with long jobs -> ECS candidate
Custom kernel/OS requirement -> EC2 candidate
- Read the result.
Output (illustrative; not executed on AWS)
Choose the simplest model that meets the requirements, then test it.
- What each part means: A candidate is not a guaranteed answer. An existing container platform may make ECS operationally simpler for a team. Bursty event work can fit Lambda; sustained workloads can have different cost trade-offs. All cost comparisons need current approximate pricing and measurements.
Ravindra Bagale's Tip
Choose the job’s model, not the newest service name.
नवीन service नाव पाहून नाही, काम पाहून निवडा.
नए service नाम से नहीं, काम देखकर चुनो.
Did you understand? Let us try it once more.