Dzine logo
Back to Blog
DevOps
8 min read

Deploy a Next.js App to AWS in 2025: A Practical Guide

Written by
Dzine Digital Team
Deploy a Next.js App to AWS in 2025: A Practical Guide

This hands-on guide shows how to deploy a production-grade Next.js application to AWS using ECS Fargate, Application Load Balancer (ALB), and GitHub Actions for CI/CD. You will containerize your app, push the image to ECR, and roll out updates safely.

1. Containerize Next.js

FROM node:20-alpine as deps
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev

FROM node:20-alpine as builder
WORKDIR /app
COPY . .
RUN npm ci && npm run build

FROM node:20-alpine as runner
WORKDIR /app
ENV NODE_ENV=production
COPY --from=builder /app/.next .next
COPY --from=builder /app/public public
COPY --from=builder /app/package*.json ./
EXPOSE 3000
CMD ["npm", "start"]

2. Push to ECR

Create an ECR repository and push images from your CI pipeline.

3. ECS Fargate Service

Define a task definition with port 3000, attach to an ALB target group, and enable health checks.

4. HTTPS

Use ACM for TLS and attach the certificate to the ALB listener on 443.

5. CI/CD

Use GitHub Actions to build, push, and update the ECS service on merge to main.

6. Observability

Send logs to CloudWatch and set scaling policies based on CPU or request count.

Tip: For static-heavy sites, consider S3 + CloudFront. For server-heavy apps, ECS or Lambda (via SST) are strong options.

Tags

#nextjs#aws#ecs#fargate#docker#ci-cd
Share:
Deploy a Next.js App to AWS in 2025: A Practical Guide | Dzine Digital