
New to AWS Series: Interviewer asks EC2 or Lambda? Server or Serverless? How to decide.
Learn when to go serverless and when not to when building on the cloud. Understand difference between Amazon EC2 instance and AWS Lambda and how to use them correctly.
Series: New To AWS Beginners Guide (5 articles)
- …
- 3New to AWS Series: Interviewer asks EC2 or Lambda? Server or Serverless? How to decide. This article
An interviewer asks: “You’re building an app that shrinks uploaded videos so they load fast on phones. Server or serverless?”
“It depends” is a good start. The useful part is what comes next.
How long does the processing take? Does it need a continuously running process? Do you need control over the operating system? And how much infrastructure do you want to manage?
Those questions matter when you build your own app, too. Let’s make servers versus serverless on AWS easier to reason about, then put the concepts to work in an EC2 guestbook and a serverless photo resizer.
The quick answer: Choose Amazon EC2 when you need control over a virtual machine or a continuously running application process. Choose AWS Lambda when your work fits event-triggered function executions and you want AWS to manage the underlying servers. The right choice depends on runtime, control, traffic, latency, and operational effort.
This guide compares EC2 with ordinary on-demand Lambda functions. AWS has other compute options, but these two make a useful starting point.
What is a server, really?
A server is a computer running software that provides something to another program, often by receiving a request and sending a response.
Open a guestbook, submit a message, and some software receives that request, saves the message, and sends a response back to your browser.
“In the cloud” describes where that computing capacity comes from. With Amazon Elastic Compute Cloud, or Amazon EC2, you can rent a virtual computer called an instance in an AWS data center.
You choose its capacity, install your application, and manage its operating system and application processes. AWS manages the physical infrastructure underneath it.
Think leasing a car: you get control over how you use it, but you still have maintenance responsibilities.
What does serverless mean on AWS?
Serverless still has servers. You work with a service that manages the underlying server infrastructure for you.
With AWS Lambda, you deploy a function: code that runs when something invokes it. That trigger could be an HTTP request, a scheduled event, or a notification that a photo arrived in Amazon S3, AWS's object storage service.
Think rideshare: you request a trip without maintaining the vehicle yourself.
You still write and maintain your application code, choose its permissions, protect its data, and monitor its behavior. Serverless reduces infrastructure work; it does not remove application ownership.

The responsibility boundary moves. Your application responsibilities remain. See the AWS shared responsibility model and Lambda runtime guidance .
EC2 vs. Lambda: the differences that matter
| Question | Amazon EC2 | On-demand AWS Lambda |
|---|---|---|
| What do you deploy? | An application on a virtual machine | A function, plus its configuration and dependencies |
| Who manages the guest operating system? | You | AWS manages the execution infrastructure; you maintain your code and dependencies |
| How does work start? | Your running application receives work | An event or request invokes your function |
| Can a process run continuously? | Yes, while the instance and process are running | Each invocation has a configured timeout, up to 15 minutes |
| How does it scale? | Resize instances or add instances, often with Auto Scaling | Lambda manages concurrent executions, within scaling and concurrency limits |
| What drives compute charges? | Running instance capacity | Requests and execution duration, with duration charges affected by configured memory |
| Where should durable data live? | Persistent storage or a database, according to your design | External durable storage, such as S3 or DynamoDB |
EC2 gives you more control over the machine. Lambda gives you less machine management. Neither guarantees a better application by itself.
What does the same app look like both ways?
Here are two simplified ways to handle a guestbook request. Both use Amazon DynamoDB to store messages so you can focus on what changes in the compute layer.
These diagrams show request paths, not complete production designs. Responses travel back to the browser; separate frontend hosting for the Lambda version is omitted.
In the EC2 version, your application process must be running to answer. In the Lambda version, Amazon API Gateway receives the HTTP request and invokes your function. A Lambda function URL is another HTTP endpoint option for some applications.
For a highly available EC2 web app, you might add an Application Load Balancer and multiple instances in an Auto Scaling group. The load balancer distributes requests; the group adjusts instance count according to configured policies and health checks. That is a useful next lesson, not a prerequisite for your first guestbook.

API Gateway can also front applications running on EC2. You do not need it merely because your app is on AWS.
Is Lambda cheaper than EC2?
Sometimes. Compare the workload and the whole architecture.
An on-demand EC2 instance incurs compute charges while it runs, including periods when your application is idle. Stopping it can stop instance compute charges, but retained storage and other resources may still cost money.
On-demand Lambda charges primarily for requests and execution duration, with duration pricing tied to the memory you configure. Duration is metered in milliseconds. During periods with no invocations, there is no invocation duration to bill, but your database, stored files, logs, or other resources may still generate charges.

Quiet periods can make on-demand Lambda attractive. Steady traffic calls for measurement, not an automatic EC2 verdict.
Include engineering time in that comparison. Patching a machine, keeping processes healthy, and configuring scaling are work, too. Conversely, function duration, memory, concurrency, and supporting services can make a Lambda design more expensive than you expected.
Check current EC2 On-Demand pricing , Lambda pricing , and the AWS Pricing Calculator . Free Tier eligibility and credits can help you experiment, but they are not a permanent cost model.
Seven questions to ask before choosing EC2 or Lambda
Ask these about the work your application performs, not just the label you give the app.

| Ask yourself | How the answer changes your choice |
|---|---|
| 1. Is this a short task triggered by an event, or a process that needs to keep running? | An uploaded image, contact-form submission, or scheduled cleanup can fit Lambda. A continuously running multiplayer game simulation points toward EC2 or another service designed for long-lived processes. |
| 2. How long does one uninterrupted unit of work actually take? | Benchmark realistic inputs. Ordinary on-demand Lambda invocations must finish within the configured timeout, up to 15 minutes. Longer work needs a different execution approach or decomposition. |
| 3. Do I need operating-system access, a GPU, or specialized machine configuration? | EC2 offers instance types and machine-level control that Lambda does not. Check specific resource requirements before choosing. |
| 4. Is traffic quiet, spiky, or busy all day? | Event-driven, intermittent traffic often suits Lambda. With steady demand, compare actual performance and total cost rather than assuming either service wins. |
| 5. How sensitive is the user experience to startup latency? | Lambda can need time to initialize a new execution environment. Measure whether that matters for your request path. EC2 also needs capacity planning and has startup time when adding machines. |
| 6. Where will durable state live, and what happens if work is retried? | Use storage or a database for durable data. For asynchronous work, design so retrying an event does not create incorrect duplicate effects. Neither compute choice removes these design tasks. |
| 7. What do I want to operate and learn? | EC2 teaches machine and process management directly. Lambda lets you focus more on functions, events, permissions, and service integration. Choose deliberately. |
If your task is short, event-driven, and fits Lambda’s resource limits, Lambda is a reasonable starting point. If you need an ongoing process or machine-level control, investigate EC2. When cost or latency determines the answer, build a small benchmark.
A useful interview answer has three parts: name the requirement, choose a service, and explain the tradeoff.
“This task runs after an upload and finishes quickly in our test, so I’d start with Lambda. We avoid managing an idle application server, but we still need retry-safe code, permissions, and monitoring.”
Back to the interview: what about the video-processing app?
Video length is not processing time.
A ten-second clip is a plausible candidate for a quick function, but the clip’s duration alone does not prove that your implementation will meet its timeout. Resolution, codec, output settings, available compute, and your code all affect processing time.
Likewise, a two-hour recording does not tell you exactly how long the processing job takes.

The stronger answer is:
“I’d benchmark representative videos, including the largest supported input. If the work fits comfortably within on-demand Lambda’s runtime and resource limits, Lambda could fit. For longer or specialized processing, I’d evaluate an EC2 worker or a managed transcoding service such as AWS Elemental MediaConvert.”
MediaConvert is a reminder that “EC2 or Lambda?” is a learning comparison, not the full AWS menu.
A timeout detail: the 15-minute limit here refers to ordinary on-demand Lambda invocations. Lambda Managed Instances has different limits for some invocation types , including up to 90 minutes for supported asynchronous invocations and event source mappings. Its operating and pricing model also differs. Keep the beginner rule scoped to the mode you are actually using.
Quick answers to common serverless interview questions
Does serverless mean there are no servers?
No. AWS runs the underlying servers. You manage your application code, configuration, permissions, and data while AWS manages the execution infrastructure.
When would you avoid on-demand Lambda?
When the workload needs a continuously running process, exceeds its execution or resource limits, requires unsupported machine-level capabilities, or fails your measured cost or latency requirements.
What is a Lambda cold start?
A cold start is the additional initialization work needed when Lambda creates a new execution environment. It does not happen on every invocation. See the Lambda execution environment lifecycle .
What does stateless mean for Lambda?
Do not depend on the next invocation reaching the same execution environment. Lambda can reuse environments, but that reuse is not a durable storage guarantee. Put messages, user state, and files in appropriate external storage. The Lambda best practices explain safe reuse and idempotency.
Does a live connection mean I need EC2?
Not automatically. A continuously running game simulation differs from a chat system that reacts to messages. API Gateway WebSocket APIs can manage connections while Lambda handles events.
How does EC2 handle more traffic?
You can use a bigger instance, called vertical scaling, or more instances, called horizontal scaling. EC2 Auto Scaling helps manage instance count. Scaling Lambda is more managed, but concurrency limits and the capacity of downstream services still matter.
Where do containers fit?
Containers package your application and its dependencies. They can run on EC2 or on a serverless container service such as AWS Fargate . Containers describe packaging; serverless describes an operational model. They are not mutually exclusive.
Make it click: build these two projects
Reading the comparison gives you vocabulary. Building both projects gives you something concrete to explain.
Start with an AWS project and your coding agent
The new AWS signup experience creates an initial project with defaults that help you get started. Follow the setup offered for your account and review its plan, credit eligibility, and spending controls.
Then connect a supported coding assistant using Agent Toolkit for AWS . It gives your agent access to AWS guidance and tools for working with resources using the permissions you authorize.
Use the agent to explain and build with you. A working deployment is useful; understanding its request path is the goal.
Start either project with this prompt:
1
2
3
4
5
6
Help me learn AWS by building a small project with Agent Toolkit for AWS.
First confirm my AWS account/project and Region. Explain the architecture,
the resources it needs, and the main sources of cost. Do not deploy yet.
Use current AWS documentation and tell me what assumptions you are making.
Create reproducible infrastructure code and a cleanup plan. Scope permissions
to the resources this project needs. Explain each step before implementing it.Project 1: build an EC2 guestbook
The idea: a simple web page where someone enters a name and message, then sees recent entries. An application on EC2 serves the page and handles its API requests. DynamoDB stores the messages.

One instance keeps the first exercise understandable. It is a learning setup, not a highly available production deployment. The IAM role authorizes access; it is not an extra hop for each request.
What you will learn: how a web server stays running, how a security group controls network access, how an EC2 IAM role gives your code AWS permissions, and why your database should not depend on the application process staying alive. You will also practice configuring logs and finding an application error.
Ask your agent:
1
2
3
4
5
6
7
8
9
Build a beginner EC2 guestbook with a small Node.js application that serves
the page and API. Store messages in DynamoDB. Give the instance an IAM role
with only the table access it needs; never put AWS credentials in the browser.
Explain a safe way for me to access the demo with minimal public exposure.
Validate and limit submitted text, escape displayed messages, and use only
test data. Configure the app to restart after a process failure or reboot.
Show me where logs go; if using CloudWatch, configure log collection explicitly.
Explain each resource and permission. Ask me to review the deployment plan
before creating resources.Then ask:
1
2
3
4
Walk me through one browser request, from submitting a message to reading it
back. Help me test that entries remain after the application process restarts.
Then explain what fails if I stop the instance and why DynamoDB data remains.
Show the resources that can still incur charges while the instance is stopped.Your finish line: save a message, restart the application, and confirm the message is still there. Explain why the app needs its server running even though the data lives elsewhere.
A guestbook does not require EC2. We chose EC2 here to learn server operations. As an extension, rebuild its API with Lambda while keeping the same DynamoDB table.
Project 2: build a serverless photo resizer
The idea: upload a photo to a private S3 input bucket. An object-created notification invokes Lambda. The function reads the original, creates a thumbnail, and writes it to a separate private output bucket.
Start by uploading through the S3 console or CLI. You do not need a frontend or API Gateway for this exercise.

The notification identifies the bucket and object key; the function then reads the image. Separate input and output buckets help prevent the function’s output from triggering itself. S3 notifications are asynchronous and can be delivered more than once , so plan for retries and duplicates.
What you will learn: event-driven execution, S3 object storage, Lambda timeouts and memory settings, execution-role permissions, logs, and handling events that may be delivered more than once. AWS’s S3 thumbnail tutorial provides a useful reference architecture.
Ask your agent:
1
2
3
4
5
6
7
8
9
10
11
12
Build a serverless photo resizer with separate private S3 input and output
buckets. Keep the input bucket and Lambda function in the same AWS Region.
Trigger an on-demand Lambda function when a supported image is
uploaded. Start with one thumbnail size and modest input limits.
Explain the event's bucket/key fields and how the function reads the image.
Scope the execution role to reading input objects, writing output objects,
and sending logs. Configure the separate permission that allows S3 to invoke
the function. Prevent output-trigger loops. Validate file types and image
dimensions, and set a suitable timeout and memory size. Use deterministic
output naming based on a unique, immutable input key for each upload, so a
repeated event for that input has a safe result. Explain this naming convention.
Show me the deployment plan, expected costs, and cleanup steps before deploying.Then ask:
1
2
3
4
Help me test one valid photo, several uploads, a repeated event, and an
unsupported file. Show me the output dimensions and the relevant logs.
Explain what happens when processing fails and how retries affect the result.
How would the design change if I needed two thumbnail sizes or larger inputs?Your finish line: upload a photo, find its thumbnail in the output bucket, and explain every step from upload to output. Be able to say why there is no application server for you to keep running between uploads.
Build it, explain it, then clean it up
After each project, ask your agent to list the resources it created, explain ongoing charges, and walk you through deleting the demo resources, including stored objects and retained logs when you no longer need them. Review the proposed deletions so you keep anything you intended to retain.
Pick one project today, then build the other. Share your architecture diagram and finish this sentence:
“I chose ___ because this workload needs ___. The tradeoff I accepted is ___.”
That is the answer worth practicing for your next interview, and the reasoning worth using for your next app.
AWS details checked October 2, 2026. Service features, pricing, limits, and account eligibility can change; the linked AWS documentation is the source of truth. All AWS service icons in the visuals come from the official AWS Architecture Icons package .
Series: New To AWS Beginners Guide (5 articles)
- …
- 3New to AWS Series: Interviewer asks EC2 or Lambda? Server or Serverless? How to decide. This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article