AWS Builder Center

AWS Cost Optimization Guide: When Should You Migrate from ECS to Lambda and Save Up to 40%?

An analysis of real-world scenarios where Serverless outperforms containers in cost and operational efficiency, including a reference architecture you can deploy today.

Estudiante de Ingenieria en Sistemas Computacionales Especialidad Cloud Computing
Choosing between Amazon ECS (or EKS) and AWS Lambda is often framed around developer preference or container packaging. However, when examining the monthly bill and operational maintenance overhead, the perspective changes dramatically.
In this article, we will look at how to identify if your current container workloads are generating unnecessary costs and how a migration strategy toward Serverless can optimize your resources without sacrificing performance.

The Problem with Idle Resources in Containers

When running microservices on Amazon ECS with AWS Fargate or EC2, you pay for the entire duration the task or instance remains running, regardless of whether it is actively processing requests or sitting idle.
If your application experiences fluctuating traffic patterns—such as high utilization during business hours and virtually zero traffic overnight—you are paying for idle capacity. While Auto Scaling helps mitigate this, there is still a minimum task threshold and a delay time required to respond to sudden traffic spikes.

When AWS Lambda Is the Right Alternative

AWS Lambda is not a silver bullet for every architecture, but it excels significantly in the following scenarios:
  1. APIs with intermittent or variable traffic: You pay strictly per millisecond of execution time.
  1. Asynchronous event processing: Event-driven integrations with Amazon S3, DynamoDB Streams, or Amazon SQS.
  1. Short-lived processing tasks: Execution workloads that run under the 15-minute limit per request.

Practical Cost Comparison

Consider a service processing 500,000 requests per month with an average response time of 200 ms:
  • Amazon ECS (Fargate): Requires running at least 2 tasks configured at  0.25 vCPU / 0.5 GB RAM  24/7 to ensure high availability across two Availability Zones.
  • AWS Lambda: Charges only for the cumulative total of those 200 ms execution blocks per request, while also taking advantage of the AWS Free Tier monthly allocation.
In low to moderate traffic scenarios, savings can exceed 40%, while also eliminating the need to manage security patches at the execution environment level.

Reference Serverless Architecture

To migrate a typical Docker-based REST API to an efficient serverless setup, the recommended stack consists of:
  1. Amazon API Gateway: Serving as the secure entry point and rate limiter.
  1. AWS Lambda: Containing the core business logic (using direct integrations or lightweight frameworks).
  1. Amazon DynamoDB: Providing low-latency storage using an On-Demand pricing model.

Community Discussion

Every architecture involves trade-offs, and cold starts remain a key topic of discussion when evaluating Lambda for specific runtimes.
  • What has been your experience when comparing operational costs between ECS and Lambda in production environments?
  • Do you consider cold starts a blocking factor for adopting Serverless in your organization today?
Drop your thoughts in the comments below with your perspective or the strategies you use in your projects. If you found this useful, a like helps keep these technical breakdowns coming for the community!
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article