# AWS Amplify Deployment Checklist

## Pre-Deployment

- [ ] Ensure all optimizations are committed to git
- [ ] Test locally: `npm run build` and `npm start`
- [ ] Verify environment variables in `.env.production`
- [ ] Review `amplify.yml` configuration

## AWS Amplify Setup

### 1. Create New App
- [ ] Go to AWS Amplify Console
- [ ] Click "New app" → "Host web app"
- [ ] Connect your repository (GitHub/GitLab/Bitbucket)
- [ ] Select branch: `main` or `production`

### 2. Configure Build Settings
- [ ] Framework: Next.js (auto-detected)
- [ ] Build command: `npm run build`
- [ ] Use `amplify.yml` from repository: ✅

### 3. Environment Variables
Set these in Amplify Console → App Settings → Environment Variables:

**Required (Private):**
```env
API_BASE_URL=https://admin.mymorni.com/api/v1
NEXTAUTH_SECRET=your-secret-here
```

**Required (Public):**
```env
NEXT_PUBLIC_APP_URL=https://your-amplify-domain.amplifyapp.com
NEXT_PUBLIC_CDN_URL=https://d2blq4bj1mzc5m.cloudfront.net
NEXT_PUBLIC_SITE_URL=https://your-amplify-domain.amplifyapp.com
```

**OAuth (if using):**
```env
GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-secret
```

### 4. Deploy
- [ ] Click "Save and deploy"
- [ ] Wait for build to complete (~5-10 minutes)
- [ ] Verify deployment at: `https://[branch].[app-id].amplifyapp.com`

## Post-Deployment

### 1. Test Functionality
- [ ] Visit library page: `/library?type=fabrics`
- [ ] Test search functionality
- [ ] Test filter functionality
- [ ] Verify images load correctly
- [ ] Check browser console for errors

### 2. Verify Caching
Open browser DevTools → Network tab:
- [ ] First request: Status 200 (from server)
- [ ] Second request: Status 304 or from cache
- [ ] Check Response Headers for `Cache-Control`

### 3. Performance Check
- [ ] Run Lighthouse audit (target: 90+ performance)
- [ ] Check Core Web Vitals
- [ ] Verify API response times (<500ms)

### 4. Monitor CloudWatch
In AWS Console → CloudWatch:
- [ ] Check Lambda invocation count
- [ ] Monitor CloudFront cache hit ratio
- [ ] Review error logs

## Custom Domain (Optional)

### 1. Add Domain
- [ ] In Amplify Console → Domain management
- [ ] Add your domain (e.g., `mymorni.com`)
- [ ] Follow DNS configuration instructions

### 2. Update Environment Variables
```env
NEXT_PUBLIC_APP_URL=https://mymorni.com
NEXT_PUBLIC_SITE_URL=https://mymorni.com
NEXTAUTH_URL=https://mymorni.com
```

### 3. Update Google OAuth
- [ ] Add production URL to Google Console
- [ ] Update authorized redirect URIs

## Cost Monitoring

### Week 1
- [ ] Check AWS billing dashboard
- [ ] Review CloudWatch metrics
- [ ] Verify cache hit rates (target: 80%+)

### Month 1
- [ ] Compare costs to estimates
- [ ] Adjust cache durations if needed
- [ ] Optimize based on usage patterns

## Optimization Checklist

### If Costs Are High
- [ ] Increase cache duration (5min → 10min)
- [ ] Check for cache invalidation issues
- [ ] Review API call patterns
- [ ] Consider static generation for high-traffic pages

### If Performance Is Slow
- [ ] Enable CDN compression in CloudFront
- [ ] Optimize images (Next.js Image component)
- [ ] Review bundle size
- [ ] Consider Edge runtime for API routes

## Rollback Plan

If issues occur:
1. [ ] In Amplify Console → Deployments
2. [ ] Find last working deployment
3. [ ] Click "Redeploy this version"

## Support

- AWS Amplify Console: `https://console.aws.amazon.com/amplify`
- CloudWatch Logs: `https://console.aws.amazon.com/cloudwatch`
- Build logs: Available in Amplify Console

---

## Success Metrics

After deployment, you should see:
- ✅ 60-80% reduction in API calls
- ✅ 80%+ CDN cache hit rate
- ✅ <500ms API response times
- ✅ 90+ Lighthouse performance score
- ✅ 60-70% cost reduction

## Notes

- Cache takes ~5 minutes to warm up
- First requests will be slower (cache miss)
- Monitor for 1 week before making changes
- Adjust cache durations based on data freshness needs
