HomeBlogHow to Deploy a Full-Stack Application...

Engineering Guide · 9 min read · November 10, 2026

How to Deploy a Full-Stack Application on AWS

Click-ops AWS setups break when a forgotten public database port, mismatched load balancer timeout, or runaway NAT bill hits at the worst moment. This guide maps a repeatable startup deployment on AWS covering VPC security group chaining, CloudFront asset delivery, ordered schema migrations, and cost controls.

Author
Smit Desai
Published
November 10, 2026
Read time
9 min read
Topic
Cloud & DevOps
Services
Custom Web · Mobile Apps · All Services

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 serve index.html with must-revalidate so 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:

  1. Secrets in SSM Parameter Store or Secrets Manager: Inject database passwords and API keys via IAM task-execution roles; never bake .env files into ECR images.
  2. 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.
  3. 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.
  4. 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.

Written by Smit Desai · Principal Full-Stack & FDSE

8+ years shipping production systems · 171 case studies · 300+ WordPress servers managed for Finland partners.

Next Steps and Recommended Resources

Next Steps · Recommended Resources

Pillar 1 · Infrastructure Proof

300+ WordPress & Cloud Server Fleet

From server-level management of 300+ WordPress sites for a Finland client to PostgreSQL query tuning (3,982 -> 52 queries).

Pillar 2 · Legacy Rescue

Upgrade Old Software (10 Hrs Free)

Audit bottlenecks, eliminate security vulnerabilities, and stabilize production servers—starting with 10 free engineering hours.

01 — Frequently asked questions

cloud & devops

Should a startup deploy full-stack apps to AWS App Runner, EC2, or ECS Fargate?

App Runner fits simple stateless services with minimal VPC rules, EC2 suits bootstrapped teams squeezing fixed monthly costs, and ECS Fargate hits the practical middle ground for multi-service apps needing rolling deploys without Linux host patching.

Why do Node.js or Python APIs randomly return HTTP 502 errors behind an AWS ALB?

An AWS Application Load Balancer uses a default 60-second idle connection timeout, whereas Node.js HTTP servers default to a 5-second keep-alive timeout. Setting your app server keepAliveTimeout above 60 seconds stops the race condition.

How should database migrations run during an ECS or container rollout?

Execute schema changes as a dedicated one-off task (aws ecs run-task) before updating the web service revision, ensuring migrations are backward-compatible so old and new containers run safely side by side.

What is the safest way to access private RDS databases from a developer laptop?

Keep RDS inside private subnets with zero public IP address and tunnel through an AWS Systems Manager (SSM) Session Manager port-forwarding session rather than opening port 5432 or managing SSH bastion keys.

03 — Have an engineering need?

hire the right expertise

Let's talk tech.

Deciding between an embedded forward deployed engineer or a senior full stack developer? Share your technical context and timeline.

Solitaire Corporate Park, Makarba, Ahmedabad, Gujarat 380015, India · IST (UTC+5:30) · --:-- IST · Mon–Fri 09:00–18:00 IST · US & EU overlap daily

No newsletter, no CRM. Just a reply.