Teams rarely regret choosing Amazon Web Services; they regret clicking through forty console screens without writing down why an inbound rule exists. Six months later, nobody dares remove 0.0.0.0/0 from a security group, staging shares credentials with production, and random 502 Bad Gateway spikes appear every time traffic climbs.
Since 2017, across 170+ shipped systems and maintaining server fleets ranging from startup APIs to 300+ live WordPress installations for a Finnish partner, I have found AWS works best when you keep the moving parts small, declarative, and tightly segmented.
1. Match the AWS Runtime to Your Team Stage
Picking an overly complex scheduler burns weeks of product runway before your first paying subscriber arrives. Match your compute layer to actual operational capacity:
| AWS Deployment Pattern | Patching & OS Burden | Fixed Baseline Cost | Rollback Reliability | Ideal Startup Stage |
|---|---|---|---|---|
| EC2 + Reverse Proxy (Caddy/Nginx) | High (OS & kernel updates owned) | Lowest ($15–$40/mo) | Scripted / manual swap | Pre-seed / solo founder |
| AWS App Runner | Zero (fully managed runtime) | Low (scales near idle) | Automatic on health fail | Single API + static frontend |
| ECS on Fargate + ALB | Zero host OS maintenance | Moderate ($45–$120/mo+) | Native circuit breaker | Seed to Series B SaaS |
| Amazon EKS (Kubernetes) | High (upgrades, CNI, add-ons) | Highest (control plane + nodes) | Helm / ArgoCD rollouts | Multi-squad platform orgs |
If you run a React/Next.js frontend, a backend API (Laravel, Node.js, or Go), a PostgreSQL database, and async workers, CloudFront + S3 + ALB + ECS Fargate + RDS delivers reliable isolation without hiring a dedicated SRE team. Review canonical reference diagrams in the AWS Architecture Center and keep container-native patterns grounded via the CNCF Blog before adding extra services.
2. Segment the VPC With Chained Security Groups
Hardcoding IP CIDR ranges inside security groups breaks the moment auto-scaling assigns new container addresses. Instead, chain security groups by reference: allow traffic into the application group only from the load balancer group, and allow traffic into RDS only from the application and worker groups.
# Terraform: chain security groups instead of opening CIDR ranges
resource "aws_security_group" "app_tasks" {
name = "prod-app-tasks-sg"
vpc_id = aws_vpc.main.id
ingress {
from_port = 8000
to_port = 8000
protocol = "tcp"
security_groups = [aws_security_group.alb.id]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_security_group" "rds_postgres" {
name = "prod-rds-sg"
vpc_id = aws_vpc.main.id
ingress {
from_port = 5432
to_port = 5432
protocol = "tcp"
security_groups = [aws_security_group.app_tasks.id]
}
}
Route AWS Backbone Traffic Around NAT Fees
Private application subnets cannot reach S3 or ECR without a path out. Routing container pulls or large file writes through a NAT Gateway triggers per-gigabyte processing fees. Attach a free S3 Gateway Endpoint to your private route tables immediately, and evaluate an ECR Interface Endpoint once image pushes exceed a few dozen gigabytes per month.
3. Serve Static Frontends Safely via CloudFront
Offload compiled JavaScript, CSS, fonts, and public media from your backend containers onto Amazon S3 fronted by CloudFront. Always block public bucket access completely and authenticate CloudFront using Origin Access Control (OAC) so nobody can bypass CDN WAF rules by hitting raw S3 URLs.
- SPA / Static Assets: Cache hashed JS/CSS files for one year (
max-age=31536000, immutable) and serveindex.htmlwithmust-revalidateso browsers pick up new chunk filenames immediately after deployment. - SSR + Unified Origins: When running Next.js or Inertia behind one domain (
app.yourdomain.com), configure CloudFront path behaviors so/assets/*hits S3 while dynamic routes and/api/*forward to your Application Load Balancer over HTTPS with ACM certificates.
4. Fix ALB Keep-Alive Races and Migration Ordering
Two subtle production bugs trip up almost every first-time AWS container launch: intermittent 502 responses and broken database rollouts.
Align Server Keep-Alive Above the ALB Idle Timeout
By default, an AWS Application Load Balancer holds idle backend connections open for 60 seconds. Node.js HTTP servers close idle sockets after 5 seconds (server.keepAliveTimeout). When the ALB reuses a pooled socket right as Node closes it, users receive an HTTP 502 error. Always set your server's keep-alive timeout to 65 seconds and headers timeout to 66 seconds.
Run Migrations Before Swapping Service Tasks
Never put php artisan migrate --force or prisma migrate deploy inside your web container's startup CMD. When ECS launches three containers concurrently, all three race to acquire schema locks. Instead, execute an explicit migration task inside your deployment script—authenticated via short-lived GitHub OIDC credentials as recommended on the GitHub Engineering Blog:
# 1. Execute one-off migration task using the newly pushed image revision
TASK_ARN=$(aws ecs run-task \
--cluster prod-cluster \
--launch-type FARGATE \
--task-definition prod-migrator:42 \
--network-configuration "awsvpcConfiguration={subnets=[subnet-aaa,subnet-bbb],securityGroups=[sg-app],assignPublicIp=DISABLED}" \
--query "tasks[0].taskArn" --output text)
# 2. Halt deployment automatically if migrations fail
aws ecs wait tasks-stopped --cluster prod-cluster --tasks "$TASK_ARN"
EXIT_CODE=$(aws ecs describe-tasks --cluster prod-cluster --tasks "$TASK_ARN" \
--query "tasks[0].containers[0].exitCode" --output text)
[ "$EXIT_CODE" -eq 0 ] || exit 1
# 3. Roll out web and worker services only after schema succeeds
aws ecs update-service --cluster prod-cluster --service prod-web --force-new-deployment
Keep web APIs and background queue workers in separate ECS services built from the same container image so memory-heavy PDF exports never stall live customer checkouts. For queue retry and memory tuning details, see our breakdown of scaling background jobs with Laravel and Redis.
5. Production Hardening Checklist Before Day-One Traffic
Lock down four operational defaults before sharing your launch URL:
- Secrets in SSM Parameter Store or Secrets Manager: Inject database passwords and API keys via IAM task-execution roles; never bake
.envfiles into ECR images. - RDS Protection & Pooling: Turn on deletion protection, 14-day automated backups, and place PgBouncer or RDS Proxy in front of PostgreSQL if auto-scaling web tasks can exceed
max_connections. - CloudWatch Retention & Budget Alerts: Set 30-day retention caps on every log group (AWS defaults to keeping logs indefinitely) and configure AWS Budgets notifications at 50% and 80% of target spend.
- Keyless Shell Access: Omit SSH key pairs and port 22 rules entirely; rely on SSM Session Manager whenever engineers need break-glass inspection—a clean discipline equally critical when managing 300+ WordPress sites at server level.
Launch Clean AWS Infrastructure With SmitDev
Clean cloud architecture stays boring during traffic spikes and painless for new engineers to inherit. Whether you are deploying a greenfield SaaS MVP or untangling legacy EC2 pet servers through an old software upgrade, SmitDev ships documented, Terraform-backed AWS setups that your team owns outright.
Work directly with a senior Full-Stack and Forward Deployed Engineer across European, UK, US, UAE, Australian, and Singapore time zones through remote software engineering, hire a developer in Europe, or flexible hourly developer models—with transparent pricing at $55/day (8–9 hours of dedicated engineering) or $1,999/month for continuous delivery. Contact SmitDev to scope your AWS launch checklist and deployment pipeline.