All articles
    Cloud Architecture

    AWS Lambda vs Containers (ECS/Fargate): When to Use Each

    June 23, 2026 8 min read
    AWS LambdaECSFargateServerlessDockerAWS

    $340/mo

    Lambda Cost for Production App

    Different Tools for Different Problems

    Lambda and ECS/Fargate are both ways to run application code on AWS. They are not interchangeable. Choosing between them requires understanding the operational model, cost structure, and architectural constraints of each, not just following a "serverless is better" or "containers give you more control" heuristic.

    Lambda: The Operational Profile

    Lambda functions are stateless, event-driven, and billed per invocation and duration. They spin up in response to a trigger (HTTP request, S3 event, queue message, scheduled event) and terminate when the handler returns. There are no servers to manage, no deployment pipelines to maintain beyond uploading code, and no capacity planning.

    The constraints are real: maximum 15-minute execution time, limited ephemeral storage (10GB), cold start latency on the first invocation after a period of inactivity, and a programming model that requires stateless, idempotent handlers.

    Cold starts: the real numbers

    Cold start latency for Node.js Lambda functions is typically 100 to 500ms for the first invocation after the function has been idle. With Provisioned Concurrency, this is eliminated for pre-warmed instances. For latency-sensitive endpoints like a login API or a checkout flow, Provisioned Concurrency is worth the cost. For background processing jobs, cold starts do not matter.

    ECS/Fargate: The Operational Profile

    ECS with Fargate runs Docker containers as long-lived tasks. Your container starts, handles requests until it stops, and Fargate manages the underlying infrastructure. Unlike Lambda, containers can run indefinitely, maintain in-memory state, and handle long-running processes.

    The operational overhead is higher than Lambda: you manage a cluster, a load balancer, health checks, scaling policies, and rolling deployments. None of this is difficult with experience, but each component is a thing that can fail and must be monitored.

    The Cost Comparison

    For The Silva Way's production serverless backend, the average monthly Lambda bill was $340. The equivalent EC2 capacity to handle the same peak load would have cost approximately $1,200 per month. Lambda's pay-per-request pricing is dramatically cheaper for workloads with spiky or low sustained traffic.

    The calculation flips for high-sustained-traffic workloads. Lambda pricing at 100 million requests per month with 500ms average duration starts to approach or exceed ECS/Fargate costs. At high, sustained request volumes, containers on ECS Fargate are cheaper because you are paying for capacity, not per-request overhead.

    The Decision Matrix

    Use Lambda when:

    • Traffic is spiky or unpredictable, with periods of near-zero load
    • Individual operations complete in under 15 minutes
    • Each request is independent and stateless
    • You do not have a dedicated DevOps function to manage cluster infrastructure
    • The workload is event-driven: S3 uploads, queue messages, scheduled jobs, API webhooks

    Use ECS/Fargate when:

    • Traffic is high and sustained with a predictable baseline
    • Processes run for more than 15 minutes (batch jobs, long-running data processing)
    • The application needs to maintain connections: WebSockets, database connection pools, in-memory caches
    • Cold starts are unacceptable and Provisioned Concurrency cost is not justified
    • You need more than 10GB of ephemeral storage during execution

    The Hidden Costs of Each

    Lambda's hidden cost is DynamoDB design complexity. To avoid Lambda's connection pool problem with RDS, most Lambda architectures pair with DynamoDB, which requires careful access pattern modeling upfront. Getting the single-table design wrong costs a week of migration work later.

    ECS/Fargate's hidden cost is the Application Load Balancer: approximately $16 per month minimum plus per-LCU charges. For low-traffic applications, the ALB can cost more than the containers it fronts. Lambda includes API Gateway routing in its pricing model, making the low-traffic cost comparison even more favorable for Lambda.

    FriendsBit has designed and operated both Lambda and ECS/Fargate architectures for production workloads. If you are choosing between them for a new service, get in touch and we will work through the specific cost and operational implications for your workload.

    K

    Khalil

    Senior Software Engineer & Founder, FriendsBit

    8+ years building enterprise software, API integrations, and cloud systems across healthcare, government, and SaaS. React, Next.js, Go, .NET, React Native, and AWS.

    LinkedIn

    Have a similar challenge?

    We've solved problems like this before. Tell us about your project and we'll get back to you within 24 hours.

    Get in touch

    Related service

    Cloud Solutions & AWS

    View service