Compute Services
Deploy applications on AWS compute services — EC2 virtual machines, Lambda serverless functions, containers with ECS/Fargate, and Elastic Beanstalk.
Amazon EC2
EC2 provides resizable virtual machines. Choose instance types by workload: general purpose (t3, m6i), compute optimized (c6i), memory optimized (r6i), and storage optimized (i3). Use Auto Scaling Groups for automatic capacity adjustment.
Launch instances with Amazon Machine Images (AMIs). Use User Data scripts for boot-time configuration. Attach Elastic IPs for static public addresses.
- t3.micro is Free Tier eligible — 750 hours/month
- Use Spot Instances for fault-tolerant workloads at up to 90% discount
- Placement Groups control instance physical placement for latency
# Launch an EC2 instance
aws ec2 run-instances \
--image-id ami-0c55b159cbfafe1f0 \
--instance-type t3.micro \
--key-name my-key \
--security-group-ids sg-0123456789 \
--subnet-id subnet-0123456789 \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=web-server}]'AWS Lambda
Lambda runs code without managing servers. Upload functions, configure triggers, and pay only for compute time used. Supports Node.js, Python, Go, Java, Ruby, and container images.
Lambda integrates with API Gateway (HTTP), S3 (events), DynamoDB (streams), SQS (messages), and EventBridge (scheduling). Cold starts affect latency — use provisioned concurrency for consistent performance.
exports.handler = async (event) => {
const body = JSON.parse(event.body);
return {
statusCode: 200,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: `Hello, ${body.name}!` }),
};
};Containers on AWS
ECS (Elastic Container Service) runs Docker containers with EC2 or Fargate launch types. Fargate is serverless — no EC2 instances to manage. ECR (Elastic Container Registry) stores Docker images.
EKS (Elastic Kubernetes Service) provides managed Kubernetes for complex orchestration needs. Choose ECS for simpler container workloads, EKS for Kubernetes-native requirements.
# Push image to ECR aws ecr get-login-password | docker login --username AWS \ --password-stdin 123456789012.dkr.ecr.us-east-1.amazonaws.com docker tag myapp:latest 123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:latest docker push 123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:latest
Elastic Beanstalk
Elastic Beanstalk handles deployment, capacity provisioning, load balancing, and health monitoring. Upload code, and Beanstalk provisions the underlying infrastructure automatically.
Ideal for getting started quickly with web applications. Supports Node.js, Python, Java, .NET, Go, PHP, and Docker. Less control than raw EC2 but significantly less operational overhead.
# Deploy with EB CLI eb init my-app --platform node.js-20 --region us-east-1 eb create production-env --instance-type t3.small eb deploy eb open
Choosing Compute Services
Use Lambda for event-driven, short-duration tasks (API backends, file processing, scheduled jobs). Use ECS/Fargate for long-running containerized services. Use EC2 when you need full OS control or specialized hardware.
Many architectures combine services: API Gateway + Lambda for APIs, ECS for background workers, EC2 for stateful databases (though managed services are preferred).
# Decision guide # Lambda: < 15 min execution, event-driven, variable traffic # Fargate: containerized, steady traffic, no server management # EC2: full control, GPU, custom AMIs, legacy apps # Beanstalk: quick deployment, standard web apps