AWS Amplify automatically deploys frontend when code is pushed to Git. This section guides you through configuring auto-deployment.
| Step | Description |
|---|---|
| 1 | Git Push → GitHub/GitLab |
| 2 | Webhook → Amplify |
| 3 | Amplify Build: Provision build environment |
| 4 | npm ci (install dependencies) |
| 5 | npm run build (Next.js build) |
| 6 | Deploy to CDN |
| 7 | Invalidate cache |
| 8 | App live at: https://main.d<APP_ID>.amplifyapp.com |
leximaincd lexi-fe
# Add hosting
amplify add hosting
# Select:
# ? Select the plugin module: Hosting with Amplify Console
# ? Choose a type: Continuous deployment (Git-based)
# Publish
amplify publish
Amplify automatically detects amplify.yml. Verify configuration:
version: 1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
- node_modules/**/*
- .next/cache/**/*
In Amplify Console → App settings → Environment variables:
NEXT_PUBLIC_API_URL=https://<API_ID>.execute-api.<REGION>.amazonaws.com/Prod
NEXT_PUBLIC_WEBSOCKET_URL=wss://<WEBSOCKET_API_ID>.execute-api.<REGION>.amazonaws.com/Prod
NEXT_PUBLIC_COGNITO_REGION=<REGION>
NEXT_PUBLIC_COGNITO_USER_POOL_ID=<USER_POOL_ID>
NEXT_PUBLIC_COGNITO_CLIENT_ID=<CLIENT_ID>
# Push code
git add .
git commit -m "Update frontend"
git push origin main
# Amplify automatically:
# 1. Detects push
# 2. Starts build
# 3. Deploys
View build progress in Amplify Console.
Amplify can deploy multiple branches:
main → Production (main.d<APP_ID>.amplifyapp.com)
develop → Staging (develop.d<APP_ID>.amplifyapp.com)
feature/* → Preview (pr-<NUMBER>.d<APP_ID>.amplifyapp.com)
Configuration:
develop)# Via CLI
amplify add domain
# Or via Console:
# 1. Domain management → Add domain
# 2. Enter domain: lexi.example.com
# 3. Configure DNS records
# 4. Wait for SSL certificate
DNS Configuration:
Type: CNAME
Name: lexi
Value: <AMPLIFY_DOMAIN>
Receive notifications when deployment succeeds/fails:
# List apps
aws amplify list-apps --region <REGION>
# Get app details
aws amplify get-app \
--app-id <APP_ID> \
--region <REGION>
# List branches
aws amplify list-branches \
--app-id <APP_ID> \
--region <REGION>
# Get build status
aws amplify list-jobs \
--app-id <APP_ID> \
--branch-name main \
--region <REGION>
Amplify automatically performs blue/green:
# Via Console:
# 1. Go to Deployments
# 2. Select previous version
# 3. Click "Redeploy this version"
# Via CLI:
aws amplify start-deployment \
--app-id <APP_ID> \
--branch-name main \
--job-id <PREVIOUS_JOB_ID>
Pull requests automatically create previews:
PR #123 → https://pr-123.d<APP_ID>.amplifyapp.com
Amplify caches node_modules and .next/cache:
cache:
paths:
- node_modules/**/*
- .next/cache/**/*
# Use npm ci instead of npm install
preBuild:
commands:
- npm ci --prefer-offline --no-audit
Amplify automatically:
# Check build logs in Amplify Console
# Common issues:
# - Missing environment variables
# - Node version mismatch
# - Build command errors
Solution:
amplify.yml syntaxnpm run buildSolution:
npm ci instead of npm install# Check DNS records
dig lexi.example.com
# Check SSL certificate
aws amplify get-domain-association \
--app-id <APP_ID> \
--domain-name lexi.example.com
Frontend CI/CD is complete! Continue to Monitoring to set up monitoring.