EC2 (Elastic Compute Cloud)
EC2 provides resizable virtual servers. You choose the instance type, OS, storage, and networking.
Launching an Instance (CLI)
# Launch a t3.micro running Ubuntu 22.04
aws ec2 run-instances \
--image-id ami-0c02fb55956c7d316 \
--instance-type t3.micro \
--key-name my-keypair \
--security-group-ids sg-0123456789abcdef \
--subnet-id subnet-0123456789abcdef \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=web-server}]'Connecting via SSH
chmod 400 my-keypair.pem
ssh -i my-keypair.pem ubuntu@<public-ip>Security Groups
Security groups are stateful firewalls at the instance level:
# Allow HTTP and HTTPS inbound
aws ec2 authorize-security-group-ingress \
--group-id sg-0123456789abcdef \
--ip-permissions \
IpProtocol=tcp,FromPort=80,ToPort=80,IpRanges=[{CidrIp=0.0.0.0/0}] \
IpProtocol=tcp,FromPort=443,ToPort=443,IpRanges=[{CidrIp=0.0.0.0/0}]Instance Types
| Family | Use Case | Example |
|---|---|---|
| t3/t4g | General purpose, burstable | Web servers, dev |
| m7i | Balanced CPU + memory | App servers |
| c7i | Compute optimised | CI runners, encoding |
| r7i | Memory optimised | Databases, caching |
S3 (Simple Storage Service)
S3 stores any file as an object inside a bucket. Objects can be up to 5TB.
Basic Operations
# Create a bucket
aws s3 mb s3://my-app-assets-20260701
# Upload a file
aws s3 cp dist/app.js s3://my-app-assets-20260701/
# Sync a directory
aws s3 sync ./dist s3://my-app-assets-20260701/dist/ --delete
# Download
aws s3 cp s3://my-app-assets-20260701/app.js ./app.js
# List
aws s3 ls s3://my-app-assets-20260701/
# Remove
aws s3 rm s3://my-app-assets-20260701/old-file.jsS3 Use Cases
- Static website hosting
- Build artifact storage (CI/CD)
- Log archiving
- Terraform state backend
- Media file storage (with CloudFront CDN)
S3 buckets are private by default. Never enable "Block Public Access OFF" unless you explicitly need a public website. Use pre-signed URLs for secure temporary access.