AWS offers several places to run code, differing in how much of the stack you operate. This page compares the options, then covers the classic building blocks: EC2 instances, Auto Scaling groups that add and remove them, and Elastic Load Balancing in front.

Choosing compute

AWS offers several places to run code. The main difference is how much of the stack you operate.

You manageNotable limits
EC2The OS, patching, scalingPer-Region instance quotas by type1
LambdaOnly the handler code15-minute timeout, 10,240 MB memory, 1,000 concurrent executions by default2
ECSTask definitions; EC2 capacity unless on FargateFargate tasks up to 16 vCPU and 120 GB3
EKSKubernetes workloads; nodes unless on Auto ModeKubernetes version lifecycle and upgrades4

Shared practice

All four notes give the workload an IAM role instead of long-term keys: EC2 instance roles, Lambda execution roles, ECS task and execution roles, and IRSA or Pod Identity in EKS.1234

Analysis: Lambda’s timeout and payload limits are the usual reason to move a job to containers, and Kubernetes compatibility or ecosystem needs are the reason to pick EKS over ECS; the notes do not compare these directly.

Amazon EC2

Amazon Elastic Compute Cloud (EC2) provides on-demand virtual servers called instances; the instance type sets the balance of compute, memory, network, and storage.1

Lifecycle and billing

StateInstance usage billing
pendingNot billed
runningPer second, 1-minute minimum
stoppingNot billed, except when hibernating
stoppedNot billed; EBS volumes and Elastic IPs still cost
shutting-down, terminatedNot billed

As tabled in the note.

ActionEffect
RebootSame host; keeps public DNS, private IP, and instance-store data
Stop/start (EBS-backed)New host; keeps private IPv4 and Elastic IP; new public IPv4; instance store erased
Hibernate (EBS-backed)RAM saved to the EBS root volume
TerminatePermanent; root volume deleted by default via DeleteOnTermination

As described in the note.1

Pricing options

On-Demand (per second, 60-second minimum), Savings Plans or Reserved Instances (1 or 3 year commitments), Spot (cheap, reclaimable), and Dedicated Hosts or Capacity Reservations.1

Practices

  • Least-privilege security groups; IAM roles instead of long-term keys; termination protection on critical instances.
  • Regular EBS snapshots and AMIs; patch through Systems Manager.1

Troubleshooting

SymptomCheck
Status check failsReboot; if it persists, stop and start
No SSH/RDPSG port 22/3389 and source, routes and NACL, OS service, key pair
Public IP changedExpected after stop/start without an Elastic IP
Instance-store data goneExpected on stop, hibernate, terminate
Burstable credits exhausted (t2/t3)Unlimited mode or a bigger type

As tabled in the note.1

Amazon EC2 Auto Scaling

An Auto Scaling group (ASG) keeps the right number of EC2 instances running. It never goes below its minimum or above its maximum; scaling policies move desired capacity within that range, and health checks replace any instance that fails. The two loops, health-driven replacement and policy-driven scaling, both launch instances from the same launch template.5

Concepts

  • Launch templates (AMI, instance type, key pair, security groups, user data); launch configurations are legacy.
  • EC2 status checks plus optional custom or ELB health checks; unhealthy instances are terminated and replaced.
  • Even spread across the chosen AZs; mixed instance types and On-Demand with Spot, with Capacity Rebalancing for Spot at risk.
  • Instance refresh for rolling or canary updates; lifecycle hooks and scale-in protection for stateful work.
  • No additional charge beyond the underlying resources.5

Practices

  • Versioned launch templates; target tracking on CPU, requests per target, or queue depth.
  • ELB health checks for application-aware replacement across several AZs.5

Troubleshooting

SymptomCheck
Not launchingTemplate validity, AZ capacity, instance type availability, IAM
Desired not maintainedScaling activities, health, unexpected scale-in protection
Policy never triggersMetric name and namespace, alarm thresholds
Instance refresh failsMinHealthyPercentage and readiness

As tabled in the note.5

Elastic Load Balancing

Elastic Load Balancing distributes incoming traffic across targets (EC2 instances, containers, IP addresses, Lambda functions) in one or more Availability Zones, sending traffic only to healthy targets and scaling automatically.

TypeLayerUse
Application Load Balancer7HTTP/HTTPS, path and host routing, WAF, Lambda targets, WebSocket
Network Load Balancer4TCP/UDP, static IPs, TLS termination, extreme throughput
Gateway Load Balancer3Route traffic through third-party virtual appliances
ClassicPrevious generation; migrate to ALB or NLB

As listed in the note.6

Concepts and practices

  • Listeners accept connections by protocol and port; target groups route to registered targets and health-check them.
  • Register targets in several AZs with cross-zone load balancing; tune health checks to reflect real application health.
  • Terminate TLS with ACM certificates; send access logs to S3; attach WAF to ALBs; pair with Auto Scaling so new instances register automatically.6

Troubleshooting

SymptomCheck
503 Service UnavailableNo healthy targets
Target unhealthyHealth check path and port, security group, the application
Connection timeoutsIdle timeout and application keepalive
NLB client IP surprisesNLB preserves client IPs, so target SGs must allow client CIDRs
Uneven distributionCross-zone setting and registration

As tabled in the note. The default quota is 20 load balancers per Region, adjustable.6

Footnotes

  1. Amazon EC2 - Runbook & Reference, original ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7

  2. AWS Lambda - Runbook & Reference, original ↩ ↩2

  3. Amazon ECS - Runbook & Reference, original ↩ ↩2

  4. Amazon EKS - Runbook & Reference, original ↩ ↩2

  5. Amazon EC2 Auto Scaling - Runbook & Reference, original ↩ ↩2 ↩3 ↩4

  6. Elastic Load Balancing - Runbook & Reference, original ↩ ↩2 ↩3