01 · Why AWS Lambda: Idle Cost, Capacity Planning and Risky In-Place Deploys

🇨🇳 中文版 | 📦 GitHub: https://github.com/geekchow/aws-lambda-guide

Where you are: Stage 1 of 6 (Why).

After this file you will know: what hurt before Lambda, why VMs and containers did not fully cure it, and which constraints shaped Lambda's design --- including why versions, aliases and provisioned concurrency had to exist.


1. The world before: you rent a server, you own its problems

Imagine ShopFast in 2012. Its checkout service runs on four EC2 (Elastic Compute Cloud) virtual machines behind a load balancer.

Pain What it looks like concretely
Paying for idle Traffic at 03:00 is 2% of peak, but all four VMs (Virtual Machines) bill 24 × 7. Typical utilization: 10--20%.
Capacity guesswork Black Friday needs 20× capacity for 6 hours. Provision too little → checkout falls over; too much → money burned for weeks of lead time.
Slow elasticity An auto-scaling group boots a new VM in minutes. A traffic spike that peaks in 30 seconds is over before help arrives.
Undifferentiated toil Kernel patches, OS (Operating System) upgrades, log agents, disk-full pages at 02:00 --- none of it is checkout logic.
Risky deploys Deploying = SSH-ing (Secure Shell) or rolling new code in place over running servers. Rollback means re-deploying the old artifact and hoping it still builds.

#mermaid-svg-LXI4zIRB8euYFvCP{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-LXI4zIRB8euYFvCP .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-LXI4zIRB8euYFvCP .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-LXI4zIRB8euYFvCP .error-icon{fill:#552222;}#mermaid-svg-LXI4zIRB8euYFvCP .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-LXI4zIRB8euYFvCP .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-LXI4zIRB8euYFvCP .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-LXI4zIRB8euYFvCP .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-LXI4zIRB8euYFvCP .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-LXI4zIRB8euYFvCP .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-LXI4zIRB8euYFvCP .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-LXI4zIRB8euYFvCP .marker{fill:#333333;stroke:#333333;}#mermaid-svg-LXI4zIRB8euYFvCP .marker.cross{stroke:#333333;}#mermaid-svg-LXI4zIRB8euYFvCP svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-LXI4zIRB8euYFvCP p{margin:0;}#mermaid-svg-LXI4zIRB8euYFvCP .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-LXI4zIRB8euYFvCP .cluster-label text{fill:#333;}#mermaid-svg-LXI4zIRB8euYFvCP .cluster-label span{color:#333;}#mermaid-svg-LXI4zIRB8euYFvCP .cluster-label span p{background-color:transparent;}#mermaid-svg-LXI4zIRB8euYFvCP .label text,#mermaid-svg-LXI4zIRB8euYFvCP span{fill:#333;color:#333;}#mermaid-svg-LXI4zIRB8euYFvCP .node rect,#mermaid-svg-LXI4zIRB8euYFvCP .node circle,#mermaid-svg-LXI4zIRB8euYFvCP .node ellipse,#mermaid-svg-LXI4zIRB8euYFvCP .node polygon,#mermaid-svg-LXI4zIRB8euYFvCP .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-LXI4zIRB8euYFvCP .rough-node .label text,#mermaid-svg-LXI4zIRB8euYFvCP .node .label text,#mermaid-svg-LXI4zIRB8euYFvCP .image-shape .label,#mermaid-svg-LXI4zIRB8euYFvCP .icon-shape .label{text-anchor:middle;}#mermaid-svg-LXI4zIRB8euYFvCP .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-LXI4zIRB8euYFvCP .rough-node .label,#mermaid-svg-LXI4zIRB8euYFvCP .node .label,#mermaid-svg-LXI4zIRB8euYFvCP .image-shape .label,#mermaid-svg-LXI4zIRB8euYFvCP .icon-shape .label{text-align:center;}#mermaid-svg-LXI4zIRB8euYFvCP .node.clickable{cursor:pointer;}#mermaid-svg-LXI4zIRB8euYFvCP .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-LXI4zIRB8euYFvCP .arrowheadPath{fill:#333333;}#mermaid-svg-LXI4zIRB8euYFvCP .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-LXI4zIRB8euYFvCP .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-LXI4zIRB8euYFvCP .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-LXI4zIRB8euYFvCP .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-LXI4zIRB8euYFvCP .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-LXI4zIRB8euYFvCP .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-LXI4zIRB8euYFvCP .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-LXI4zIRB8euYFvCP .cluster text{fill:#333;}#mermaid-svg-LXI4zIRB8euYFvCP .cluster span{color:#333;}#mermaid-svg-LXI4zIRB8euYFvCP div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-LXI4zIRB8euYFvCP .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-LXI4zIRB8euYFvCP rect.text{fill:none;stroke-width:0;}#mermaid-svg-LXI4zIRB8euYFvCP .icon-shape,#mermaid-svg-LXI4zIRB8euYFvCP .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-LXI4zIRB8euYFvCP .icon-shape p,#mermaid-svg-LXI4zIRB8euYFvCP .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-LXI4zIRB8euYFvCP .icon-shape .label rect,#mermaid-svg-LXI4zIRB8euYFvCP .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-LXI4zIRB8euYFvCP .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-LXI4zIRB8euYFvCP .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-LXI4zIRB8euYFvCP :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} Lambda 2014
After: function-centric
Traffic curve
Environments created

per concurrent request
Pay per request

and per ms
Provider patches and scales;

you publish versions
Before: server-centric
Traffic curve
Fixed fleet sized

for the peak
80 percent idle

capacity, paid
You patch, scale,

deploy in place

Caption: the shift Lambda made --- from sizing a fleet to letting capacity follow concurrent requests.

2. Why the existing answers were not enough

Predecessor What it fixed What it left broken
Physical servers --- Everything above, plus weeks of procurement.
VMs (EC2) + Auto Scaling Minutes instead of weeks; pay by the hour/second Still pay for idle; still patch an OS; scale-out takes minutes; scaling unit is a whole VM.
Containers (ECS/Kubernetes) Faster start, denser packing, immutable images You still operate a cluster (nodes, control plane, autoscalers); scale-to-zero is not native; capacity planning moves to the node pool.
PaaS (Platform as a Service, e.g. Heroku/Elastic Beanstalk) No OS patching Still sized in long-running instances ("dynos"); idle instances still bill.

The common limitation: the unit of capacity is a long-running server , so somebody must decide how many to keep running before demand arrives.

3. The constraints that shaped Lambda

To make "run code only when an event happens" a reality, a design must satisfy several constraints at once --- and each constraint explains a piece of Lambda you will meet later:

Constraint Consequence in Lambda's design Where you meet it
Scale to zero, scale to thousands, per request Capacity unit = one execution environment serving one request at a time; concurrency is the scaling metric. 05.4
Strong multi-tenant isolation at high density Each environment is a Firecracker microVM (micro Virtual Machine) --- VM-grade isolation with container-like startup. 05.6
Creating environments on demand costs latency The cold start exists. Some workloads cannot tolerate it → provisioned concurrency (pre-warmed environments). 05.3
The provider runs your code, so code must be reproducible Deployments become immutable versions: an exact, frozen snapshot of code + configuration. 05.1
Callers must not change every time you deploy A stable name that can be re-pointed → aliases, which also enable canary traffic shifting and instant rollback. 05.2
A runaway function must not take down its neighbors Account-level and per-function concurrency limits, throttling with HTTP (Hypertext Transfer Protocol) 429. 05.4
Pay only for what runs Billing in GB-s (Gigabyte-seconds) at 1 ms granularity, plus per request. 02 What

4. The "someone would have to invent it" test

If Lambda did not exist and you had to build "run my code on every event, pay nothing when idle", you would be forced to invent:

  1. a router that receives an event and decides whether it is allowed to run (limits),
  2. a pool of isolated sandboxes that can be found warm or created cold,
  3. a way to freeze what code runs so the provider can create identical sandboxes at any time (versions),
  4. a stable name callers use while the code behind it changes (aliases), and
  5. a knob to pre-create sandboxes for latency-sensitive paths (provisioned concurrency).

That list is the concept map of 03 Concept map.

Conclusion

The pain was never "servers are hard" in the abstract; it was that capacity had to be decided before demand arrived and deploys mutated live servers. Lambda answers the first with per-request, concurrency-based scaling in microVMs, and the second with immutable versions behind movable aliases. Cold starts are the price of the first answer; provisioned concurrency is the escape hatch.


Next → 02 What · Back to 00 Overview


📚 Back to series index

相关推荐
workflower2 小时前
超算中心聚焦高性能计算场景(HPC)
大数据·网络·人工智能·机器人·云计算·汽车
workflower15 小时前
Agentic AI 时代的企业ICT 基础设施运维
运维·人工智能·机器学习·重构·云计算·汽车
Geek-Chow18 小时前
00 · AWS Lambda 心智模型学习指南:总览、思维导图与阅读路线(专栏目录)
云计算
Geek-Chow21 小时前
07 · AWS Lambda 自测题与动手实验:用 AWS CLI 验证版本、别名、预置并发与冷启动
云计算
yyuuuzz1 天前
云服务器部署 web 项目的进程常驻记录
运维·服务器·前端·阿里云·云计算·aws
略懂而已2 天前
腾讯云COS 自动同步 for windows
windows·云计算·腾讯云
逐流人2 天前
Redis内存数据库:从数据类型到集群部署
linux·运维·数据库·redis·缓存·云计算
tianbin9112 天前
大模型流式输出异常排查,API 中转站层面的问题定位思路
后端·云计算