Skip to content
Back to Deployment

AWS Amplify Hosting for Full-Stack Apps

Git-connected hosting for Next.js SSR, Amplify backend (auth, data, storage), and CI/CD on AWS.

PlatformsIntermediate

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

1. Install CLI — npm i -g @aws-amplify/cli, then amplify configure with AWS credentials 2. Init project — amplify init in frontend repo, creates amplify/ backend config + env 3. Add backend — amplify add auth (Cognito), add api (AppSync GraphQL), add storage (S3) 4. Push backend — amplify push provisions CloudFormation stacks, outputs aws-exports.js 5. Connect hosting — Amplify Console → Host web app → connect repo, set build + start commands 6. Branch deploys — each git branch gets its own backend env (dev/staging/prod) automatically 7. CI/CD — Amplify Console builds on push, runs tests, deploys; customize with amplify.yml 8. Custom domain — add in console, Route53 or external DNS with CNAME to amplifyapp.com

Example

# amplify.yml — CI/CD build spec (in repo root) version: 1 backend: phases: build: commands: - amplify push --yes frontend: phases: preBuild: commands: - npm ci build: commands: - npm run build artifacts: baseDirectory: .next files: - '**/*' cache: paths: - node_modules/**/* - .next/cache/**/* # CLI workflow — adding auth + GraphQL API # amplify add auth # > Default configuration (Cognito User Pool + Identity Pool) # amplify add api # > GraphQL # > Continue editing? Yes — edit schema.graphql # amplify push // schema.graphql — AppSync schema type Todo @model @auth(rules: [{allow: owner}]) { id: ID! title: String! completed: Boolean! owner: String } // Frontend usage — generated hooks import { withAuthenticatorator } from "@aws-amplify/ui-react"; import { listTodos } from "./graphql/queries"; function App({ signOut, user }) { const { data } = useQuery(listTodos); return <div>Hello {user.username} <button onClick={signOut}>Sign out</button></div>; } export default withAuthenticatorator(App);

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.