name: deploy description: Builds, validates, and deploys all infrastructure to AWS. Creates real AWS resources that may incur costs. disable-model-invocation: false
Deploy — Ship to AWS
You are deploying the user's infrastructure to AWS using CDK. This creates real cloud resources.
Prerequisites
- CDK project exists and compiles (
cdk synthsucceeds) - At least the API stack is configured
- AWS CLI is installed and configured with credentials
What To Do
Phase 1: Pre-Flight Checks
Run these checks and report results:
AWS CLI configured?
aws sts get-caller-identity- If fails with "expired token" or "credentials": Explain "Your AWS session has expired. If you're using SSO, run
aws sso loginto refresh it. SSO sessions typically last 8-12 hours." - If fails with "not configured": Guide the user through
aws configure sso - If succeeds: Show the account ID and region, confirm with the user: "I see you're connected to account [ID] in [region]. Is this the right account?"
- If fails with "expired token" or "credentials": Explain "Your AWS session has expired. If you're using SSO, run
CDK compiles?
cd infrastructure && npx cdk synth- If fails: Debug the issue
Common mistake scan:
- Check for wildcard IAM permissions
- Check for public S3 bucket policies
- Check for hardcoded secrets
- Check for missing CORS configuration
- Report any issues found
Phase 2: Plan
Show the user exactly what will be created:
Run
cdk diff:cd infrastructure && npx cdk diffTranslate the diff into plain language:
- "This will create [N] Lambda functions..."
- "This will create an API Gateway with [N] routes..."
- "This will create a DynamoDB table..."
- "This will create a CloudFront distribution..."
- etc.
Cost estimate:
- List each resource and its free-tier eligibility
- Estimate monthly cost for low traffic (likely $0-5)
- Remind about cleanup: "Ask me to tear down the resources when you're done to avoid charges"
Explain CDK Bootstrap: If this is the first CDK deployment in this account/region: "CDK needs a one-time setup called 'bootstrap' — it creates an S3 bucket that CDK uses to store deployment assets. This is required and costs virtually nothing."
Phase 3: Confirm
Get explicit confirmation before deploying: "I'm about to create the following AWS resources in account [account-id], region [region]:"
- List each resource
- "This may incur costs. Shall I proceed?"
Wait for user confirmation. Do NOT proceed without it.
Phase 4: Execute
Bootstrap CDK (if needed):
cd infrastructure && npx cdk bootstrapExplain what's happening
Deploy all stacks:
cd infrastructure && npx cdk deploy --all --require-approval never --outputs-file ../.migration/outputs.json- Set time expectations: "Deployment typically takes 3-5 minutes. CloudFront distributions take the longest — up to 5-10 minutes on the first deploy. You'll see progress updates as each resource is created."
- Stream progress and explain what's being created
--require-approval neverbecause we already confirmed with the user--outputs-filesaves stack outputs for reference
Handle errors:
- If deployment fails, read the error, explain it in plain language, and suggest fixes
- "Access Denied" → "Your AWS user doesn't have permission to create this resource. If you're using SSO, check that your role has admin permissions. If your session expired mid-deploy, run
aws sso loginand try again." - "Resource already exists" → "A previous deployment left this resource behind. Check the AWS CloudFormation Console — you may need to delete a stuck stack before redeploying."
- "ExpiredToken" → "Your AWS session expired during deployment. Run
aws sso loginto refresh, then try deploying again. CDK will pick up where it left off." - Timeout → "Some resources take time to create. CloudFront can take up to 15 minutes. This is normal — just wait."
Phase 5: Post-Deploy
Display outputs: Read
.migration/outputs.jsonand display:- CloudFront URL (the website)
- API Gateway URL
- Cognito User Pool ID and Client ID (if auth deployed)
- DynamoDB table name (if database deployed)
Update frontend config:
- Generate
config.jswith the API URL from outputs - Upload to S3
- Invalidate CloudFront cache
- Generate
Test the deployment:
- Try to access the CloudFront URL
- Try a simple API call
- Report results
Guide the user:
- "Your app is live! Visit [URL] to see it"
- "Try the API at [URL]/api/..."
- "To run comprehensive tests, tell me to test the deployment"
- "When you're done, ask me to tear down the resources to stop costs"
Update
.migration/plan.mdto mark deploy as complete
Important Notes
Safety
- ALWAYS confirm before deploying
- Show the account ID to prevent deploying to wrong account
- Run
cdk diffbeforecdk deployto show what changes - Save outputs for reference and teardown
Cost Awareness
- Most resources have free-tier eligibility — mention this
- Lambda: 1M free requests/month
- API Gateway: 1M free calls/month
- DynamoDB: 25 GB free storage, 25 read/write units
- S3: 5 GB free storage
- CloudFront: 1 TB free data transfer
- Reminder: free tier is per-account, 12 months for new accounts
Troubleshooting Common Deploy Issues
- "Access Denied" → Check IAM permissions for the deploying user
- "Resource already exists" → Stack may be in a broken state, may need manual cleanup
- "Timeout" → Some resources take time (CloudFront can take 5-15 minutes)
- "Limit exceeded" → Account service limits, may need to request increases