AWS Compute Services: A Comprehensive Guide

Amazon Web Services offers a diverse portfolio of compute services designed to handle every possible workload—from traditional virtual servers to serverless functions and container orchestration. Understanding these options is critical for architecting cost-effective, scalable applications.


1. EC2 (Elastic Compute Cloud) – Virtual Servers in the Cloud

EC2 is the foundational compute service that provides resizable virtual machines. It offers the most control but requires the most management overhead.

Instance Types (The "Family" System)

AWS organizes EC2 instances into families optimized for specific workloads:

FamilyCodeUse Case
General Purposet, mWeb servers, development environments (t4g, m7i)
Compute OptimizedcBatch processing, gaming servers, ad serving (c7i)
Memory Optimizedr, xDatabases, in-memory caches (r7i, x2idn)
Storage Optimizedi, dData warehouses, NoSQL databases (i4i, d3)
Accelerated Computingp, gMachine learning, graphics rendering (p5, g5)

Example: Launching a t4g.small instance (ARM-based Graviton)

aws ec2 run-instances \
--image-id ami-0c7217cdde317cfec \
--instance-type t4g.small \
--key-name my-key \
--subnet-id subnet-0a1b2c3d4e5f67890 \
--count 1

Purchasing Options

OptionDescriptionBest For
On-DemandPay by the hour/secondShort-term, unpredictable workloads
Reserved Instances1-3 year commitment, up to 72% discountSteady-state applications
Spot InstancesBid on unused capacity, up to 90% discountFault-tolerant, stateless workloads
Savings PlansFlexible commitment across compute servicesMixed workloads with consistent usage

User Data: Automating Bootstrapping

You can run scripts when an instance first launches:

#!/bin/bash
# This script installs Apache and serves a custom webpage
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo "<h1>Hello from EC2 at $(hostname -f)</h1>" > /var/www/html/index.html

Launch with User Data:

aws ec2 run-instances \
--image-id ami-0c55b159cbfafe1f0 \
--instance-type t2.micro \
--user-data file://bootstrap.sh

2. AWS Lambda – Serverless Functions

Lambda runs code in response to events without provisioning servers. It automatically scales from zero to thousands of concurrent executions.

Supported Runtimes

  • Node.js, Python, Java, Go, Ruby, C#, PowerShell
  • Custom runtimes via Runtime API

Key Concepts

ConceptDescription
Memory128 MB to 10,240 MB (allocates proportional CPU)
TimeoutUp to 900 seconds (15 minutes)
ConcurrencyDefault soft limit: 1,000 executions per region
Ephemeral Storage512 MB to 10,240 MB in /tmp

Advanced Example: S3-Triggered Image Processor

Lambda Function (Python):

import boto3
import urllib.parse
import os
from PIL import Image
s3 = boto3.client('s3')
def lambda_handler(event, context):
# Get bucket and key from S3 event
bucket = event['Records'][0]['s3']['bucket']['name']
key = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'])
# Download original image
download_path = f'/tmp/{key}'
s3.download_file(bucket, key, download_path)
# Create thumbnail
with Image.open(download_path) as img:
img.thumbnail((128, 128))
thumb_path = f'/tmp/thumb_{key}'
img.save(thumb_path)
# Upload thumbnail to different bucket
thumb_bucket = f'{bucket}-thumbnails'
s3.upload_file(thumb_path, thumb_bucket, f'thumb_{key}')
return {
'statusCode': 200,
'body': f'Created thumbnail for {key}'
}

Deployment Package:

pip install pillow -t .
zip -r function.zip .
aws lambda create-function \
--function-name image-resizer \
--runtime python3.11 \
--role arn:aws:iam::123456789012:role/lambda-s3-role \
--handler lambda.lambda_handler \
--timeout 30 \
--memory-size 1024 \
--zip-file fileb://function.zip

3. ECS (Elastic Container Service) – Container Orchestration

ECS is AWS's native container orchestration service for running Docker containers at scale.

Launch Types

Launch TypeDescriptionUse Case
FargateServerless, no EC2 managementSimplicity, variable workloads
EC2You manage the underlying instancesCost optimization, dedicated hosts

Core Components

┌─────────────────────────────────────────────┐
│              ECS Cluster                    │
│  ┌───────────────────────────────────────┐  │
│  │            Service                    │  │
│  │  (Maintains task count, load balancer)│  │
│  │  ┌─────────────────────────────────┐  │  │
│  │  │           Task                  │  │  │
│  │  │  ┌─────────┐    ┌─────────┐    │  │  │
│  │  │  │Container│    │Container│    │  │  │
│  │  │  │   (Web) │    │   (Sidecar)│  │  │  │
│  │  │  └─────────┘    └─────────┘    │  │  │
│  │  └─────────────────────────────────┘  │  │
│  └───────────────────────────────────────┘  │
└─────────────────────────────────────────────┘

Task Definition Example (JSON)

{
"family": "web-app",
"networkMode": "awsvpc",
"executionRoleArn": "arn:aws:iam::123456789012:role/ecsTaskExecutionRole",
"containerDefinitions": [
{
"name": "nginx",
"image": "nginx:latest",
"memory": 512,
"cpu": 256,
"essential": true,
"portMappings": [
{
"containerPort": 80,
"protocol": "tcp"
}
],
"environment": [
{
"name": "ENVIRONMENT",
"value": "production"
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/web-app",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "web"
}
}
}
],
"requiresCompatibilities": ["FARGATE"],
"cpu": "256",
"memory": "512"
}

Deploy Task:

aws ecs register-task-definition --cli-input-json file://task-def.json
aws ecs run-task --cluster production --task-definition web-app

4. EKS (Elastic Kubernetes Service) – Managed Kubernetes

EKS provides managed Kubernetes control planes with integration into AWS services.

Key Features

  • Managed Control Plane: AWS handles etcd, API server, and scheduler
  • Node Options: Self-managed EC2, Managed Node Groups, or Fargate
  • Add-ons: VPC CNI, CoreDNS, kube-proxy, and marketplace integrations

Quick Setup with eksctl

# Install eksctl
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
# Create a cluster
eksctl create cluster \
--name my-cluster \
--region us-east-1 \
--nodegroup-name standard-workers \
--node-type t3.medium \
--nodes 3 \
--nodes-min 1 \
--nodes-max 4 \
--managed

Deploying an Application to EKS

# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.25
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: LoadBalancer
selector:
app: nginx
ports:
- port: 80
targetPort: 80

Apply to cluster:

kubectl apply -f deployment.yaml
kubectl get services  # Returns LoadBalancer DNS name

5. AWS Batch – Managed Batch Processing

Batch runs thousands of batch computing jobs across EC2 instances, dynamically scaling based on volume.

Job Definition Example

{
"jobDefinitionName": "data-processor",
"type": "container",
"containerProperties": {
"image": "123456789012.dkr.ecr.us-east-1.amazonaws.com/data-processor:latest",
"vcpus": 2,
"memory": 4096,
"command": ["python", "process.py", "--input", "Ref::s3Input"],
"environment": [
{"name": "OUTPUT_BUCKET", "value": "my-results-bucket"}
],
"executionRoleArn": "arn:aws:iam::123456789012:role/batch-execution-role"
},
"retryStrategy": {
"attempts": 3
},
"timeout": {
"attemptDurationSeconds": 3600
}
}

Submit a Job:

aws batch submit-job \
--job-name my-job-001 \
--job-queue high-priority-queue \
--job-definition data-processor:1 \
--parameters '{"s3Input": "s3://my-data/input.csv"}'

6. Lightsail – Simplified Compute for Beginners

Lightsail is the easiest AWS compute service, offering pre-configured virtual servers with predictable pricing ($3.50–$100+/month).

What You Get

  • Virtual server (similar to EC2 but simplified)
  • Static IP
  • DNS management
  • SSD storage
  • One-click installs (WordPress, LAMP, Node.js)

Create via CLI:

aws lightsail create-instances \
--instance-name my-website \
--availability-zone us-east-1a \
--blueprint-id wordpress \
--bundle-id nano_3_0

7. AWS Elastic Beanstalk – PaaS for Developers

Elastic Beanstalk abstracts infrastructure entirely. You upload code, and AWS handles capacity provisioning, load balancing, auto-scaling, and monitoring.

Supported Platforms

  • Java, .NET, Node.js, PHP, Python, Ruby, Go
  • Docker containers
  • Custom platforms

Deploying a Node.js Application

Application Structure:

my-app/
├── app.js
├── package.json
└── .ebextensions/
└── nodecommand.config

Deploy:

# Install EB CLI
pip install awsebcli
# Initialize application
eb init -p node.js my-app --region us-east-1
# Create environment and deploy
eb create my-app-env

Configuration File (.ebextensions/options.config):

option_settings:
aws:autoscaling:launchconfiguration:
InstanceType: t3.medium
EC2KeyName: my-key
aws:elasticbeanstalk:environment:
EnvironmentType: LoadBalanced
aws:elasticbeanstalk:application:environment:
NODE_ENV: production
DATABASE_URL: postgres://...

8. AWS Outposts – Hybrid Cloud Compute

Outposts brings native AWS services to on-premises data centers, enabling a consistent hybrid experience.

Use Cases

  • Low-latency workloads requiring on-premises data residency
  • Local data processing (factories, retail stores)
  • Migration with legacy dependencies

9. AWS Wavelength – Edge Compute for 5G

Wavelength embeds AWS compute within 5G network edges, enabling ultra-low latency applications (1–10 ms).

Ideal For

  • Autonomous vehicles
  • AR/VR applications
  • Real-time gaming
  • Industrial automation

Comparison Matrix: Choosing the Right Compute Service

ServiceAbstraction LevelManagement OverheadScaling SpeedBest For
EC2IaaS (Infrastructure)HighMinutesFull control, legacy apps
LambdaFaaS (Serverless)NoneMillisecondsEvent-driven, intermittent workloads
ECSCaaSMediumSecondsDocker containers, microservices
EKSCaaS (Kubernetes)Medium-HighSecondsKubernetes ecosystem, portability
BatchManaged BatchLowMinutesHigh-performance computing, data processing
LightsailSimplified IaaSVery LowMinutesSimple websites, beginners
Elastic BeanstalkPaaSLowMinutesDevelopers who don't want infrastructure management
OutpostsHybridHighN/AOn-premises with AWS APIs

Cost Optimization Strategies

  1. Right-sizing: Use CloudWatch metrics to identify underutilized instances and downgrade
  2. Spot Instances: For stateless workloads, save up to 90% over On-Demand
  3. Savings Plans: Commit to $X/hour of compute usage across EC2, Fargate, and Lambda
  4. Graviton Processors: ARM-based instances are 20% cheaper and 20% more efficient
  5. Lambda Provisioned Concurrency: Pay for idle capacity to eliminate cold starts (use only when necessary)

Next Steps

  • Networking: Explore VPC, subnets, and security groups to secure your compute resources
  • Storage: Pair compute with EBS (block storage), EFS (file storage), or S3 (object storage)
  • Monitoring: Set up CloudWatch dashboards and alarms for all compute services
  • Automation: Use Infrastructure as Code (CloudFormation, Terraform, CDK) to provision compute resources repeatably

Leave a Reply

Your email address will not be published. Required fields are marked *


Macro Nepal Helper