AWS Amplify Hosting for Full-Stack Apps
Git-connected hosting for Next.js SSR, Amplify backend (auth, data, storage), and CI/CD on AWS.
Why
Amplify Hosting pairs a Next.js/Astro/React frontend with an AWS backend (Cognito auth, AppSync GraphQL, S3 storage, DynamoDB) in one git-connected pipeline. It avoids wiring 8 AWS services manually while keeping you on AWS for compliance, VPC peering, and enterprise IAM.
When
Choose Amplify when you need AWS backend services (Cognito, AppSync, DynamoDB) with a frontend, enterprise compliance (HIPAA, FedRAMP), or VPC integration. Skip for static-only sites (Cloudflare/Vercel cheaper) or non-AWS backends.
How
Example
Common Problems
- ⚠amplify push fails with CloudFormation error — usually a name collision or IAM permission gap in the deploy role
- ⚠Next.js SSR routes 502 — Amplify Hosting needs compute role, or app uses Node API not supported
- ⚠aws-exports.js regenerated on every push — committing it causes merge conflicts, gitignore it
- ⚠Cold start on Lambda resolvers — first GraphQL query takes 2-3s, use provisioned concurrency
Best Practices
- ✓Use amplify env for per-stage isolation — dev/staging/prod get separate Cognito + DynamoDB
- ✓Gitignore aws-exports.js — it's regenerated per environment, committing causes drift
- ✓Set IAM deploy role with least privilege — avoid using admin credentials in CI
- ✓Enable provisioned concurrency on hot Lambda resolvers — eliminates cold start for GraphQL
FAQ
How is Amplify Hosting different from S3+CloudFront?
Amplify Hosting is a managed layer over S3+CloudFront that adds git-based deploys, PR previews, and instant cache invalidation. S3+CloudFront is more flexible but you manage the pipeline. Use Amplify for speed, raw S3+CF for control.
Why is my Next.js app not working on Amplify?
Amplify Hosting supports Next.js SSR via Amplify's compute, but only certain versions. Check the framework support matrix. For App Router or edge runtime, use the amplifyHosting compute mode or deploy on Vercel instead.
How do I set environment variables per branch?
In Amplify Console, set Branch to scope. Backend environments (amplify push) have separate env vars from frontend hosting — configure both. Use AWS Secrets Manager for secrets.
Why is my deploy stuck at Provisioning?
Amplify is provisioning CloudFront and Lambda resources, which can take 5-15 min on first deploy. Subsequent deploys are faster. If stuck over 20 min, check CloudFormation in the AWS console for a failed stack.
How do I customize the CloudFront distribution Amplify creates?
You can't directly — Amplify manages it. For custom headers or redirects, use a customHttp.yml file in the app root. For full CloudFront control, eject to S3+CloudFront and manage manually.