Use AWS Lambda for compatible event-driven or HTTP workloads when measured performance and full costs favor managed execution. Choose EC2 when the application needs server-level control, specialized or persistent capacity, or lower cost from provisioned instances. A hybrid fits systems with both kinds of work. Demand, required availability, and actual bills can shift the answer, so pilot the chosen design against your existing baseline before you move production.
AWS Lambda vs EC2: the decision in 60 seconds
Sort each workload first: independent events, an HTTP service, continuous processing, or work that needs control of the underlying server. A CPU-intensive job that runs occasionally and an Express booking API that serves requests all day have different utilization, even if both apps are small. Match each component to its execution pattern and operational needs before you pick infrastructure. For Savings Plans, Reserved Instances, and utilization coverage, use the Savings Plans versus Reserved Instances commitment analysis to compare the requirements.
What EC2, Lambda Event Functions, Web Functions, and Managed Instances provide
Amazon EC2 gives you virtual-machine capacity that you configure and operate. AWS Lambda runs your code through managed execution services, and the newer models differ in HTTP behavior, capacity ownership, and billing. The Lambda model you pick can change what once looked like a simple choice between short functions and an always-running server.
AWS introduced Lambda Web Functions on October 12, 2026. Its Web Functions announcement describes Node.js applications, including Express and Hono, running as port-listening HTTP servers with concurrent requests and streaming.
| Compute model | Execution and concurrency | Responsibility and billing |
|---|---|---|
| Lambda Event Functions | Discrete events and invocations; a conventional execution environment handles one invocation at a time. | Managed execution; request count and billed resource duration, plus any extras. |
| Lambda Web Functions | Supported Node.js HTTP servers; concurrent requests can share an environment, with HTTP streaming support. | Managed HTTP execution; requests, active vCPU time, environment-memory residency, transfer, and supporting services. |
| Lambda Managed Instances | Lambda functions run on AWS-managed EC2-backed capacity with concurrent invocations. | Request charges, underlying EC2 instance charges, a capacity management fee, and supporting infrastructure. |
| Amazon EC2 | Applications and persistent processes run on provisioned virtual machines. | You control the guest OS and processes; instance capacity, network, storage, resilience, and operating labor add to cost. |
One Event Function might process a queue item, while a Web Function keeps the server model of a supported Node.js HTTP framework. EC2 gives your team ordinary VM administrative control. Lambda Managed Instances use EC2 capacity in your account, but AWS manages the instance lifecycle, so you don’t get the host administration of a self-managed EC2 instance.
For Managed Instances, AWS documents a management fee of 15% of the applicable EC2 On-Demand instance price. Eligible EC2 discounts can cut the underlying capacity cost but not that fee. When you publish a function version to a Managed Instances capacity provider, Lambda normally launches three instances for Availability Zone resilience. Attaching a function to a running provider can reuse available capacity without launching more.
At launch, AWS named US East (N. Virginia), US East (Ohio), and US West (Oregon), alongside Tokyo and Ireland, as supported Regions. Your deployment must use a Region and runtime that your chosen configuration supports.
Lambda MicroVMs serve a specialized isolated-code execution use case and bill by the instance-second. They fall outside this comparison of ordinary API and background work.
Which hard limits rule out a compute model?
Check limits before prices. A cheaper billing model won’t fix a missing host privilege, an unsupported runtime, or a synchronous run that’s too long.
The AWS Lambda quotas documentation separates the execution models:
- Event Function duration: Standard invocations run up to 900 seconds, or 15 minutes.
- Managed Instances duration: Eligible asynchronous invocations and event-source mappings can run up to 90 minutes. Amazon MQ and Amazon DocumentDB event sources are excluded from that extension.
- Event Function resources: Standard memory extends to 10,240 MB. The default Regional concurrency quota is 1,000, subject to account-specific settings and service limits.
- Web Function HTTP timeout: The request timeout defaults to 30 seconds and is configurable from 3 to 900 seconds. The execution environment has a 10-second initialization timeout.
- Web Function resources: AWS documents 2 GB of memory and 2 vCPUs per execution environment, with 64 concurrent requests per environment by default and a configurable range from 1 to 128.
- Host-level requirements: Kernel-level components, specific GPU capabilities, continuously controlled processes, or an incompatible runtime call for EC2 or a different supported architecture.
Say an image-processing job needs 17 uninterrupted minutes. That’s over the standard Event Function limit. An asynchronous Managed Instances invocation can run that long if the trigger and other limits qualify. A service that needs custom guest-OS components has a separate problem: raising Lambda’s memory setting won’t give you ordinary VM administrative privileges.
For each workload, write down its maximum duration, trigger, runtime, memory and CPU needs, state, host privileges, concurrency, and Region. Drop any option that fails a requirement.
Compare equivalent workloads, not headline hourly prices
Compare completed work at the same service level. Include idle EC2 capacity and the work completed per Lambda invocation when you assess throughput, response time, resilience, and cost.
| Input | Measurement to collect | Why it changes the choice |
|---|---|---|
| Request arrivals | Requests per hour, daily variation, and burst concentration | Determines idle instance capacity and Lambda demand peaks |
| Execution profile | p50/p95 duration, active CPU, and downstream I/O waiting | Separates computation from time spent awaiting dependencies |
| Resource needs | Runtime, memory, CPU architecture, and required hardware | Prevents false equivalence between unlike processing capacity |
| Service level | Peak concurrency, recovery time, uptime objective, and Availability Zones | Specifies comparable resilience and throughput |
| Supporting services | Storage, load balancing, egress, NAT, logs, and retries | Accounts for charges outside the main compute resource |
An EC2 burstable T-class instance and a Lambda configuration with similar memory can supply different CPU capacity. CPU-credit behavior, architecture, and sustained throughput affect how much work each completes. An app that needs multi-AZ resilience should also count the EC2 redundancy and load-balancing resources that provide it.
A September 2026 SUE experiment examined how downstream waiting affects the cost of an I/O-sensitive workload. Its result applies to the tested setup only, so work from your measured demand and performance, not a universal price ratio.
Cost break-even and engineering overhead
Cost crossover depends on request frequency, actual compute use, provisioned capacity, and the infrastructure around them. Price each model from its own billing components before you decide to switch platforms.
| Model | Estimate structure | Costs to include |
|---|---|---|
| Lambda Event Functions | Requests × request rate + billed duration and allocated-resource charges | Initialization, provisioned concurrency, networking, logs, and integrated services |
| Lambda Web Functions | Requests × request rate + active vCPU-seconds × CPU rate + memory residency × memory rate | Transfer, observability, and supporting services |
| Lambda Managed Instances | Requests × request rate + EC2 instance capacity at the applicable rate + management fee based on the EC2 On-Demand price | Storage, networking, monitoring, utilization, and eligible compute discounts |
| EC2 | Instance running time × applicable rate | EBS, load balancers, redundancy, backup, transfer, monitoring, and operator time |
EC2 On-Demand pricing bills per second with a 60-second minimum for applicable instance configurations. A running instance keeps consuming billable capacity while the app sits idle. The Managed Instances formula must also carry request charges: AWS lists $0.20 per million requests in its referenced US pricing schedule, with the relevant price scope and any exclusions.
AWS also standardized INIT-phase billing effective August 1, 2025, for affected on-demand managed ZIP runtimes. For those configurations, an estimate that leaves out initialization misstates billed execution.
For Web Functions, elapsed HTTP response time and active CPU time play separate roles. AWS gives an illustrative server-side rendering example in US East (N. Virginia) on Arm: 15 million monthly requests, 150 milliseconds of end-to-end response time, 40 milliseconds of active CPU, and approximately 500 MB of memory.
With one environment resident throughout a 30-day month, the published calculation assigns $16.62 to active vCPU, $4.66 to execution-environment memory, and $4.50 to requests, totaling $25.78. This AWS Lambda pricing example excludes free-tier and data-transfer effects.
An application that spends much of each request waiting on APIs can see different economics under Web Function active-CPU accounting than under Event Function duration-based accounting. Count memory residency, requests, and supporting services either way.
Hello, pretty new to building on AWS so I pretty much just threw everything in lambda for the heavy compute and have light polling on EC2. I am doing all CPU and somewhat memory intensive work that lasts around 1-7 minutes on async lambda functions, which sends a webhook back to the polling bot (free t2 micro) when it is complete. For my entire project, lambda is accruing over 50% of the total costs which seems somewhat high as I have around 10 daily users on my service.
The author also described the engineering cost of learning to run asynchronous workers on EC2. Count that migration effort in the decision, since operating savings take time to repay it.
For an ongoing monthly comparison, include compute, downstream services, required resilience, and operating labor. Treat one-time migration work separately or amortize it over a stated period. Use dated rates for your Region and measured usage under both intermittent and sustained demand.
The wider cloud workload cost estimate covers storage, network transfer, and services beyond the Lambda or EC2 compute line. No universal request count makes one option cheaper; workload distribution, platform, Region, discounts, and service-level requirements decide.
Latency and cold-start diagnosis
If an endpoint is slow, find out where the time goes: initialization, handler work, downstream API or database calls, or network transfer. Each one can cause the delay your users see.
I am creating a Slack Bot. Slack commands require a response in 3 seconds. My runtime is Python 3.9 with 128MB of RAM. Most of you guys were right, it wasn’t the cold start that was actually the problem, but the stuff I was doing inside the Function (a few API calls, mostly to Slack). I assumed it was the cold start, because without the cold start and locally it was executing quick enough. I solved it for now by using a lambda that sends the payload to the queue which returns a 200. The message will then trigger another lambda function that will process the payload.
The developer’s Slack integration had to acknowledge within three seconds. A queue let the first handler return promptly while a second Lambda invocation did the slow work. That design adds queue and duplicate-delivery responsibilities.
When initialization is the bottleneck, supported SnapStart configurations or provisioned concurrency can cut startup latency. Each has its own eligibility rules and cost. Neither shortens the time a handler spends waiting for a database or remote API.
CloudWatch metrics and traces expose each interval. Trace one representative request from entry point to completion, separating INIT, handler processing, downstream I/O, and response delivery. Then compare p95 and p99 under ordinary demand and bursts against the endpoint’s response deadline before you change its compute model.
Latency-sensitive API criteria
Supported Node.js services can run as Lambda Web Functions and keep familiar HTTP server frameworks, including Express and Hono. That suits server-side-rendered pages, login routes, webhook receivers, and booking apps with ordinary request-response semantics. Web Functions don’t support WebSocket upgrades. Server-sent events handle one-way streaming, and native WebSocket connections need a compatible endpoint or a separate service.
Several HTTP requests can share one Node.js execution environment. Keep request-specific user data in request-scoped variables or middleware context, because shared mutable globals can leak or corrupt data across concurrent requests. CPU-heavy synchronous work blocks the event loop and delays other in-flight requests.
Specify the API contract once: HTTP framework and runtime, streaming and connection needs, session-state assumptions, response deadline, and required concurrency. Match that contract to Web Functions or EC2 before you choose on price.
Concurrency, retries, and failure recovery
Scaling adds execution capacity. How the app copes with duplicate events and a slow database depends on retry settings, idempotency, and backpressure.
- Event Function Regional quota: The account quota limits how much eligible work runs concurrently.
- Event Function reserved concurrency: This allocates or limits concurrent execution for a function; setting it to zero stops new event processing.
- Event Function provisioned concurrency: This prepares supported execution environments to reduce startup latency.
- Web Function request concurrency: Each environment handles multiple requests, up to its configured per-environment limit and subject to endpoint scaling controls.
- Managed Instances concurrency: Multiple eligible invocations share managed EC2-backed capacity, so instance availability and utilization affect scaling.
Asynchronous Lambda invocations may be retried, and the same logical event can be delivered more than once. Say a webhook writes a payment record, then fails before acknowledging the work. A later delivery repeats the side effect unless the operation is idempotent.
Queues, controlled retry policies, failure destinations, and dead-letter queues support recovery. Behavior depends on the event source: a queue poller and a directly invoked asynchronous function follow different failure and retry paths.
EC2 workloads need health checks, recovery, and Auto Scaling policies too. Extra application instances can push more work into an already constrained database, so capacity planning has to count dependency throughput and backpressure.
Test duplicate delivery, a failing dependency, and a short traffic burst against an explicit availability objective. Check that the app keeps the correct business result, limits repeated work, and recovers without overwhelming dependent services.
API startup, abuse protection and guardrails
A public API needs controls for legitimate bursts, unwanted requests, application capacity, and unexpected cost. That holds for Lambda and EC2, though the billable resources and native controls differ.
My traffic will be relative low. I’ll start my project in June with v1. It will be a booking engine something similar to calendly. It is based on express.js. Do you recommend Lambda or EC2 based infrastructure? I would use Lambda, but I worry about two things regarding to it: 1. When my API is somehow hit with DDoS then the expenses will explode because it is based on request count. I am not sure how reliable Lambda+CloudFront is, for example does it stop DDoS HTTP requests with always changing date ranges in the query string? 2. Cold start might be too slow.
This developer was planning an Express booking product and worried about future traffic abuse; no attack or runaway bill had occurred. Variable appointment-date queries matter because ordinary users can produce many distinct URLs without malicious intent.
For Event Functions, reserved concurrency limits how many invocations run at once. Web Functions have endpoint-level rate throttling through throttleConfig.rateLimit and execution-environment ceilings through scalingConfig.maxEnvironments. Neither one caps your bill.
Put a supported front door such as CloudFront in front of the API, with AWS WAF rules or other request filters and an origin-access configuration that prevents bypass. Application authentication, authorization, and rate rules cover a different part of the request path.
Set billing alerts, anomaly monitoring, and a documented incident response for the public endpoint. Unwanted traffic costs money in both designs, through Web Function charges or through EC2 instance, load-balancer, and network costs.
Network path and shared responsibility
Lambda and EC2 apps both depend on VPC routes, security controls, load balancers, and other network infrastructure outside the execution environment. A function can initialize fine and still time out because its request crosses a separate firewall, reaches a private dependency, or hits a bad route.
Network reachability and full application success can exercise different ports, policies, identities, and intermediaries. Network charges can also include NAT gateways, inter-AZ transfer, load balancing, or other data movement, depending on topology.
Managed execution moves some host tasks to AWS. Your team still owns access policy, dependency configuration, application timeouts, and diagnosis.
Trace one failing request from the entry point through the subnets, routing and security rules to the dependency and back, then compare that path with its billed network components. A dedicated guide to AWS VPC subnets and routing covers subnet routes, security groups, and NAT gateways.
Choose Lambda, EC2, or a hybrid architecture
One application often holds several independent workloads that deserve different compute choices. A persistent API, nightly image processing, webhooks, and scheduled exports share a product but need not share an execution model. Before you change Docker images, container networks, or persistent volumes, review the Docker web-application deployment and persistence guide for the implications.
| Workload situation | Candidate deployment | Condition that changes the choice |
|---|---|---|
| Intermittent scheduled tasks or queue consumers | Lambda Event Functions | Duration, resource caps, throughput, or observed total cost |
| Supported Node.js HTTP servers and SSR | Lambda Web Functions | Runtime or connection eligibility, request timeout, latency, or memory residency cost |
| High-volume functions suited to managed EC2 capacity | Lambda Managed Instances | Capacity minimums, request and management charges, or host-control requirements |
| Persistent services or specialized application environments | EC2 | Equivalent managed execution meets the same requirements at a better total cost |
| Persistent core API plus separable background work | Hybrid EC2 and Lambda | Integration, observability, and operating complexity outweigh the benefit |
A hybrid keeps a stable API on EC2 and gives independent scheduled jobs, webhook processing, or data transformations their own Lambda deployment. The cost is more boundaries between services: logging, permissions, and release coordination.
What I’d do differently: 1. Cold starts are real For user-facing API endpoints, cold starts of 500ms-2s were noticeable. I ended up keeping those on EC2. Provisioned concurrency helps but adds cost. 2. Debugging is harder Distributed tracing across 20+ Lambda functions is painful. Invested heavily in structured logging and X-Ray, but it’s still harder than debugging a monolith. 3. VPC Lambda = hidden costs Putting Lambda in a VPC for database access added complexity and cold start time. ENI attachment delays were brutal early on. VPC improvements have helped but it’s still not instant. 4. Don’t migrate everything My initial plan was to go 100% serverless. That was naive. Some workloads (WebSockets, long-running processes, stateful operations) are genuinely better on traditional servers.
The contributor describes a hybrid system that kept the main Express API and WebSockets on EC2 and moved discrete background jobs to Lambda. The post predates Web Functions.
Validate the deployment decision
Pilot measurements should cover completed work, p95/p99 latency, compute and downstream-service bills, recovery behavior, operating effort, and migration and rollback complexity, all under representative traffic and the same service requirements you set earlier.