In AWS you can easily create a RESTful API using API Gateway. With a serverless approach, you would have API Gateway integrate with Lambda to handle your endpoint logic. This seems like the most obvious approach, as its very elastic and cost effective, however, looking into architectures for large companies, most of them use a form of EC2 to handle their API logic.

Here are some examples:

  • McDonald's uses ECS instead of Lambda for their API.
  • Under Armor, uses an Application Load Balancer with EC2.

What is the benefit of using EC2 for your API instead of Lambda?

  • 6
    At sufficient scale, FaaS gets pretty expensive. It also represents some amount of lock-in to a specific platform, and limits how you can architect your applications: no in-process background tasks, you must instead trigger other functions or put everything into a message queue. If you have long-term predictable load, renting VMs can come with decent discounts. Large orgs can attain significant savings through internal sharing of resources.
    – amon
    Feb 26, 2021 at 6:00
  • In my (admittedly small) experience, lambda startup time is a significant barrier, especially with inconsistent load. I've seen attempted workarounds to try to keep lambdas warm (so we don't need to incur startup cost over and over again), but at a certain point, using EC2 is more consistent.
    – Daniel
    Mar 2, 2021 at 6:45

2 Answers 2


Why EC2, some points:

  1. More control

EC2 allows for more control on what is running on the hardware like specific tech versioning etc. EC2 allows for custom provisioning. Lambda is more hands off or automatic, fewer choices but less to manage, provision and scale.

  1. You want some sort of data recovery. EC2 allow you to recover data on the box.

  2. You have a need for VPC or other security access restrictions and want to take advantage of built in firewalls for EC2.

In general Lambda's are an event driven architecture built on top of the AWS SDK. For example, I drop a message to a SQS queue and then want to do something with it. Some systems are more complex than firing and responding to events so an EC2 may be a better fit.

It depends on what you are trying to achieve. If you have a long running process or complex processing, EC2 may be a better fit. If I recall the process timeout for a lambda is 5 or 15 minutes. Not that a typical restful API call would take that long, but hopefully that illustrates some of the differences between the two approaches.


In a lot of cases, the EC2 infrastructure was migrated from an on-prem infrastructure, and EC2 maps better to their existing/previous server setup.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.