Based on the discussion in the comments I'm now adding a complete answer to this, as this is not really suitable for a comment.

You mentioned that your current service is already running on EC2 and you'd like to move that over to a Serverless solution. Furthermore you mention the options of "Lambda or Serverless exposed via API-Gateway". Then you add some additional information about expecting a response time of 500ms and the Lambda doing 2 DynamoDB calls.

I'll address these points in order:

EC2 vs Serverless Solution:

You seem to have already decided on trying the Serverless route, which works quite well in principle for a Microservice-Type architecture you're describing. I'm not going to focus too much on the merits of the EC2 solution here. Going serverless can have the following benefits (among others):

  • Cost effectiveness: You pay only for the resources your code consumes while it's running and not for idle times
  • Scalability: Lambda scales horizontally, fast and effortlessly - you basically don't worry about it (up to 1000 parallel "instances")
  • Lower operational overhead: No need to patch operating systems - AWS takes care of that for you
  • Focus on your business logic, leave the heavy lifting of managing the infrastructure to AWS

Lambda or Serverless exposed via API-Gateway

Serverless isn't really an AWS Service but a paradigm or architectural pattern so these options don't completely make sense - you'd use the API Gateway to trigger Lambda functions whenever an Event (read: HTTP-Request) occurs. This means you'll setup a fully-managed REST-Endpoint (API-Gateway) to call your code (Lambda) on demand.

On Performance

A response time of 500ms is realistic for the use case you're describing - DynamoDB advertises single-digit-millisecond latency, so two calls to it within 500ms shouldn't be a problem. Unfortunately Lambda cold-start is a thing. Lambda scales out with parallel requests, meaning a new Micro-VM gets provisioned if there aren't enough warm instances of your function available to serve your request. This takes time, but in your use-case this shouldn't be an issue, since you don't need access to a VPC (in that case it would take multiple seconds).

Lambda is limited in performance compared to EC2 instances, you scale the amount of performance Lambda provides by specifying the amount of RAM the function gets allocated (CPU resources are provided based on the RAM). For a simple Login-Service this shouldn't be an issue as well.

I suggest you read up on the points I mentioned in the Lambda documentation (which is quite good).

Answer from Maurice on Stack Overflow
Top answer
1 of 3
11

Based on the discussion in the comments I'm now adding a complete answer to this, as this is not really suitable for a comment.

You mentioned that your current service is already running on EC2 and you'd like to move that over to a Serverless solution. Furthermore you mention the options of "Lambda or Serverless exposed via API-Gateway". Then you add some additional information about expecting a response time of 500ms and the Lambda doing 2 DynamoDB calls.

I'll address these points in order:

EC2 vs Serverless Solution:

You seem to have already decided on trying the Serverless route, which works quite well in principle for a Microservice-Type architecture you're describing. I'm not going to focus too much on the merits of the EC2 solution here. Going serverless can have the following benefits (among others):

  • Cost effectiveness: You pay only for the resources your code consumes while it's running and not for idle times
  • Scalability: Lambda scales horizontally, fast and effortlessly - you basically don't worry about it (up to 1000 parallel "instances")
  • Lower operational overhead: No need to patch operating systems - AWS takes care of that for you
  • Focus on your business logic, leave the heavy lifting of managing the infrastructure to AWS

Lambda or Serverless exposed via API-Gateway

Serverless isn't really an AWS Service but a paradigm or architectural pattern so these options don't completely make sense - you'd use the API Gateway to trigger Lambda functions whenever an Event (read: HTTP-Request) occurs. This means you'll setup a fully-managed REST-Endpoint (API-Gateway) to call your code (Lambda) on demand.

On Performance

A response time of 500ms is realistic for the use case you're describing - DynamoDB advertises single-digit-millisecond latency, so two calls to it within 500ms shouldn't be a problem. Unfortunately Lambda cold-start is a thing. Lambda scales out with parallel requests, meaning a new Micro-VM gets provisioned if there aren't enough warm instances of your function available to serve your request. This takes time, but in your use-case this shouldn't be an issue, since you don't need access to a VPC (in that case it would take multiple seconds).

Lambda is limited in performance compared to EC2 instances, you scale the amount of performance Lambda provides by specifying the amount of RAM the function gets allocated (CPU resources are provided based on the RAM). For a simple Login-Service this shouldn't be an issue as well.

I suggest you read up on the points I mentioned in the Lambda documentation (which is quite good).

2 of 3
0

If you want your events driven service managed use AWS Lambda, you just provide the code in the required language, and Amazon AWS does the rest. If you want to customise for your own needs and use whatever coding language you prefer Amazon EC2 offers flexibility and a whole range of EC2 Instance types to choose from, in conjunction with Elastic Beanstalk services for deploying onto Amazon EC2.

AWS Lambda is a service for running code in response to events, such as changes to data in an Amazon S3 bucket and Amazon DynamoDB tables, or as compute services to run your code in response to HTTP requests using Amazon API gateway or API calls made by using AWS SDKs. This is an ideal computing platform for applications when running within the standard runtime environment.

Lambda should be your best bet.

🌐
Reddit
reddit.com › r/aws › lambda vs ec2 costs for api
r/aws on Reddit: Lambda vs ec2 costs for API
August 7, 2023 -

Hi everyone I have a question regarding cost between lambda and ec2 I am building a simple node application using puppeteer that will only act as an api. Obviously don’t expect heavy usage for now but overall Iv read that lambda will be cheaper to run up until heavy usage? Just wanted to get your thoughts if ec2 is better than lambda both in performance and cost. Again this will not be heavily used in either case. Also which ones performance will be better?

🌐
Intellizu
intellizu.com › articles › aws-lambda-vs-ec2
AWS Lambda vs EC2 | Serverless vs Traditional Compute | Intellizu
November 20, 2025 - Each API request triggers a Lambda function, scales automatically, and requires no server management. For APIs with variable traffic, this model is often more cost-effective and operationally simpler than managing EC2 instances behind a load balancer.
🌐
CBT Nuggets
cbtnuggets.com › blog › certifications › cloud › aws-lambda-vs-ec2-which-to-use-and-when
AWS Lambda vs EC2: Which to Use and When
AWS Lambda is the perfect solution for any event-driven situation. Event driven means that the code is executed based on some external trigger. For instance, maybe you want a lambda to trigger when a file is uploaded to the cloud. Or maybe you want a particular lambda to run every time an API is called.
🌐
Reddit
reddit.com › r/aws › using lambda vs ec2 for a backend
r/aws on Reddit: Using Lambda vs EC2 for a backend
April 22, 2019 -

Hello everyone, I was studying for my AWS CSAA exam and while I’ve sightly used both services and played around with them in lab environments, I can’t wrap my head around one question. When would I use a EC2 over a Lambda when Lambda is much cheaper and still provides scalability for a backend solution. For most simple web apps, a REST API served thru Lambda seems like a great option (esp when utilizing AWS API Gateway). When would I directly use EC2 (as well as ELB, ASG,etc)? I guess I’m trying to understand stand when a “serverless” web app makes sense. Thanks everyone for your time

EDIT: added serverless clarification

🌐
NAKIVO
nakivo.com › cloud › aws lambda vs. amazon ec2: which one should you choose?
AWS Lambda vs. Amazon EC2: Comprehensive Comparison
April 28, 2026 - It is possible to configure encryption between a Lambda function and S3 as well as between an API gateway and Lambda with a KMS key. When you create a Lambda function, a default encryption key is created. However, the recommendation is to create your own KMS key. Compared to EC2 instances, Lambda functions don’t require security updates and patches.
Find elsewhere
🌐
Medium
medium.com › @repobaby › a-practical-guide-for-when-to-choose-lambda-over-ec2-1173160bd8ec
A practical guide for when to choose Lambda over EC2 | by RepoBaby | Medium
October 1, 2025 - For example, core business apps that need steady uptime or custom configurations often stay on EC2. Meanwhile, background jobs, data pipelines, and API endpoints that see spiky traffic tend to run better on Lambda.
🌐
DEV Community
dev.to › learnwithprashik › ec2-vs-lambda-when-to-use-which-with-real-examples-4n00
EC2 vs Lambda — When to Use Which (With Real Examples) - DEV Community
March 20, 2026 - ... AWS handles everything else automatically. If your application needs to be running 24/7 — EC2 is the right choice. ... # EC2 is perfect for this: # A Node.js API server running all day node server.js # Runs continuously on EC2
🌐
Windframe
windframe.dev › home › blog › aws ec2 vs lambda: which one should you actually use?
AWS EC2 vs Lambda: Which One Should You Actually Use?
December 18, 2025 - If you care more about convenience, just write code and let AWS deal with the rest, Lambda wins. It’s built for microservices, APIs, event-driven systems, and workloads that don’t run 24/7.
🌐
Sedai
sedai.io › home › blog › comparing aws lambda eks ecs ecs factors in system design and cost management
Lambda vs EKS vs ECS vs EC2: A Practical Comparison | Sedai
March 21, 2026 - Here’s how Lambda, EKS, ECS, and EC2 stack up in terms of purpose and scalability: ... AWS Lambda is built for event-driven applications, where specific events like an API request or a file upload trigger tasks or operations.
🌐
Hakky Handbook
book.st-hakky.com › hakky handbook › ec2 vs ecs vs lambda: a comparison from the perspective of api serving
EC2 vs ECS vs Lambda: A Comparison from the Perspective of API Serving | Hakky Handbook
April 4, 2026 - While EC2 can reduce costs by purchasing reserved instances, it requires more management and maintenance and can be more expensive than ECS or Lambda. ECS allows easy container management and automatic scaling based on traffic changes.
🌐
Leyaa
leyaa.ai › home › aws lambda vs ec2: key differences and when to use each
AWS Lambda vs EC2: Key Differences and When to Use Each | Leyaa.ai
March 9, 2026 - Lambda is great for APIs, data processing, and automation. Choose EC2 when you need full control over the server environment, run long-lasting applications, or require custom software and operating systems.
🌐
Lumigo
lumigo.io › home › aws lambda vs ec2: compared on performance, cost, security, and more
AWS Lambda vs EC2: Compared on Performance, Cost, Security, and More - Lumigo
June 25, 2024 - The downstream system’s application integration could cause timeouts in an application running on EC2 · If you don’t configure security groups appropriately, it may also cause timeout errors. AWS Lambda: Lambda has significant timeout constraints (read our guide to AWS Lambda timeout). If you have long-running workloads, Lambda may not be the right choice as it has a hard timeout limit of 15 minutes. Also, if you have a Lambda function exposed as REST API through API Gateway, it has a timeout limit of 29 seconds at the gateway.
🌐
Jeevi Academy
jeeviacademy.com › home › blogs › aws › aws ec2 vs. lambda: which is right for your project?
AWS EC2 vs. Lambda: Which Is Right for Your Project? - Jeevi Academy
November 25, 2025 - AWS EC2 is ideal for scenarios where you need full control over your compute environment, or when running stateful, long-running applications that require persistent infrastructure.
🌐
Medium
promatics.medium.com › aws-lambda-vs-aws-ec2-how-to-choose-one-over-another-77e6380ac8fc
AWS Lambda Vs AWS EC2: How to choose one over another? | by Promatics Technologies | Medium
January 12, 2021 - Lambda can also be invoked through API Gateway to expose the function code as a REST API. b.) There is no need for forecasting of the resources (CPU, Memory, Storage, etc.). c.) AWS Lambda can scale resources up and down automatically, which makes it the epitome of server-less · d.) It reduces the idle time of computing resources when the application is not in use. e.) Lambda logs can be monitored through Cloud Watch, like EC2.
🌐
Dashbird
dashbird.io › home › aws lambda vs ec2: a comparative guide
AWS Lambda / EC2: Which Is Best? | Dashbird
July 25, 2023 - Moreover, if your application requires long-running processes, complex computations, or specific operating system configurations, EC2’s flexibility and control over the computing environment make it a better choice. On the other hand, consider a scenario where you’re building a microservices-based application or a real-time file processing system. In this case, AWS Lambda would be a more suitable choice. For example, if you’re building a real-time image processing application where users upload photos and you need to process those photos (resize, apply filters, etc.) in real-time, AWS Lambda would be ideal.
🌐
Reddit
reddit.com › r/aws › lambda vs ec2 for rate limited api calls?
r/aws on Reddit: Lambda vs EC2 for rate limited API calls?
August 17, 2022 -

I'm trying to determine whether using lambdas or an EC2 instance is right for my use case. Here are the details:

We fetch our data from an external source, process it, then store it in our database. For the external source, they allow a maximum of one request every 20ms, or 50 requests per second. Most of the processing that calls this system can be done asynchronously, and there are small bursts every 15 minutes along with larger bursts when we trigger a data fetch.

Option 1 - EC2: I could set this up as a persistent server with Express or the like routing the requests to fetch the correct data from the provider. On the plus side, it would be very easy to throttle my requests to a max of one every 20ms. On the downside, it's a single instance that needs to handle burst traffic, and may slow down. In addition, I'd be paying for the instance to always be up, and if there were ever an uncaught exception, fetching our source data would be stopped until I brought the server back up.

Option 2 - Lambda: I could set this up as a lambda function with a maximum scaling number of something like 5 to 10. No matter how I throttled each lambda function, I still couldn't ensure that two functions wouldn't fire a request within a 20ms period, as they're not aware of each other. When this happens, I'd receive a spike arrest error from the provider, and would need to add handling in my code to retry the call. On the plus side, I could save money with lambdas since the traffic bursts before falling off to nearly zero. On the downside, it would add a little complexity to my code and potentially upset the provider if they need to send me regular spike arrest errors.

I'm new to AWS and have a feeling there are some things I'm not considering. Based on the above information, would you choose one of the above options or recommend something else?