Choosing a Compute Target
EC2 vs ECS/Fargate vs EKS vs Lambda vs Amplify β how to pick where your app runs.
The single biggest deployment decision is where your code runs. Each option trades control for convenience, running from a full virtual machine you manage (EC2) to fully managed frontend hosting (Amplify).
Quick guide
| Option | Best for |
|---|---|
| EC2 | Legacy apps, full OS control, special software. |
| ECS Fargate | Containerized web services without managing servers. |
| EKS | Teams already invested in Kubernetes. |
| Lambda | Event-driven, spiky, or low-traffic workloads. |
| Amplify / Beanstalk | Frontends and simple apps you want deployed fast. |
Example
# A decision heuristic in pseudocode
if purely_static_frontend: use S3 + CloudFront (or Amplify)
elif event_driven_or_low_traffic: use Lambda
elif containerized_service: use ECS Fargate
elif needs_full_os_control: use EC2
elif heavy_kubernetes_investment: use EKSWhen to use it
- A team chooses ECS Fargate for a containerised API because they want no server management but need persistent connections that Lambda cannot provide.
- A startup picks Lambda for an image-resizing service because it runs infrequently and paying per invocation is cheaper than keeping a server warm.
- An enterprise migrates a monolithic Java app to EC2 first because it requires full OS control and a custom JVM configuration.
More examples
Launch a t3.micro EC2 instance
Creates a single EC2 virtual machine β the compute target that gives maximum OS control.
aws ec2 run-instances \
--image-id ami-0c55b159cbfafe1f0 \
--instance-type t3.micro \
--key-name my-keypair \
--security-group-ids sg-0abc123 \
--count 1Deploy a Lambda function
Deploys a Lambda function β the serverless compute target where you pay only for execution time.
aws lambda create-function \
--function-name resize-image \
--runtime nodejs20.x \
--role arn:aws:iam::123456789012:role/lambda-exec \
--handler index.handler \
--zip-file fileb://function.zipCreate an ECS Fargate service
Starts a Fargate service β containers without managing the underlying EC2 fleet.
aws ecs create-service \
--cluster my-cluster \
--service-name api \
--task-definition api:3 \
--desired-count 2 \
--launch-type FARGATE \
--network-configuration \
'awsvpcConfiguration={subnets=[subnet-abc],securityGroups=[sg-xyz],assignPublicIp=ENABLED}'
Discussion