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

OptionBest for
EC2Legacy apps, full OS control, special software.
ECS FargateContainerized web services without managing servers.
EKSTeams already invested in Kubernetes.
LambdaEvent-driven, spiky, or low-traffic workloads.
Amplify / BeanstalkFrontends and simple apps you want deployed fast.

Example

Example Β· bash
# 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 EKS

When 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.

Example Β· bash
aws ec2 run-instances \
  --image-id ami-0c55b159cbfafe1f0 \
  --instance-type t3.micro \
  --key-name my-keypair \
  --security-group-ids sg-0abc123 \
  --count 1

Deploy a Lambda function

Deploys a Lambda function β€” the serverless compute target where you pay only for execution time.

Example Β· bash
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.zip

Create an ECS Fargate service

Starts a Fargate service β€” containers without managing the underlying EC2 fleet.

Example Β· bash
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

  • Be the first to comment on this lesson.
Choosing a Compute Target β€” AWS Deployment | SoundsCode