This guide covers deploying DocuMind to AWS and tearing down all resources.
Before deploying, ensure you have:
-
AWS CLI configured with credentials
aws configure
-
AWS CDK installed globally
npm install -g aws-cdk
-
Docker running (for building container images)
-
Node.js 20+ and Java 21+ installed
-
OpenAI API Key ready
cd infra
npm install
npx cdk bootstrapcd infra
npx cdk deployThis creates:
- VPC with public/private subnets
- ECS Fargate cluster with backend service
- RDS PostgreSQL database with pgvector
- S3 buckets (frontend assets + documents)
- CloudFront CDN
- Secrets Manager secrets
- Application Load Balancer
Deployment takes ~15-20 minutes.
After deployment, CDK outputs important values:
Outputs:
DocuMindStack.CloudFrontUrl = https://xxxxxx.cloudfront.net
DocuMindStack.ApiUrl = http://DocuMi-Backe-xxxxx.us-east-1.elb.amazonaws.com
DocuMindStack.FrontendBucketName = documind-frontend-xxxxx
DocuMindStack.DocumentsBucketName = documind-documents-xxxxx
DocuMindStack.DatabaseEndpoint = documindstack-xxxxx.rds.amazonaws.com
DocuMindStack.OpenAiSecretArn = arn:aws:secretsmanager:...
aws secretsmanager put-secret-value \
--secret-id documind/openai-api-key \
--secret-string '{"apiKey":"sk-your-actual-openai-key"}'aws ecs update-service \
--cluster documind-cluster \
--service documind-api \
--force-new-deploymentcd frontend
npm install
npm run buildUpload to S3 (replace with your bucket name from outputs):
aws s3 sync dist/ s3://documind-frontend-YOUR_ACCOUNT_ID-YOUR_REGION/ --deleteGet your CloudFront distribution ID:
aws cloudfront list-distributions --query "DistributionList.Items[*].{Id:Id,Domain:DomainName}" --output tableInvalidate cache:
aws cloudfront create-invalidation --distribution-id YOUR_DIST_ID --paths "/*"Open the CloudFront URL from the deployment outputs.
cd infra
npx cdk diffcd infra
npx cdk destroyType y when prompted to confirm deletion.
Destruction takes ~10-15 minutes.
Check that resources are deleted:
# Check S3 buckets
aws s3 ls | grep documind
# Check ECS clusters
aws ecs list-clusters | grep documind
# Check RDS instances
aws rds describe-db-instances --query "DBInstances[*].DBInstanceIdentifier" | grep documind
# Check CloudFront distributions
aws cloudfront list-distributions --query "DistributionList.Items[*].DomainName"
# Check Secrets Manager
aws secretsmanager list-secrets --query "SecretList[*].Name" | grep documindIf any resources remain:
Delete S3 buckets:
aws s3 rb s3://documind-frontend-ACCOUNT-REGION --force
aws s3 rb s3://documind-documents-ACCOUNT-REGION --forceDelete Secrets:
aws secretsmanager delete-secret --secret-id documind/openai-api-key --force-delete-without-recovery
aws secretsmanager delete-secret --secret-id documind/db-credentials --force-delete-without-recoveryDelete CloudWatch Log Groups:
aws logs delete-log-group --log-group-name /ecs/documind-apiIf you don't plan to use CDK again in this account/region:
# Delete the CDKToolkit CloudFormation stack
aws cloudformation delete-stack --stack-name CDKToolkit| Service | Configuration | Cost |
|---|---|---|
| ECS Fargate | 0.5 vCPU, 1GB RAM | ~$15-20 |
| RDS PostgreSQL | db.t3.micro, 20GB | ~$15-20 |
| NAT Gateway | Data processing | ~$30-40 |
| ALB | Basic usage | ~$20 |
| CloudFront | Low traffic | ~$1-5 |
| S3 | Minimal storage | ~$1-2 |
| Secrets Manager | 2 secrets | ~$1 |
| Total | ~$85-115/month |
- NAT Gateway is the biggest cost - consider VPC endpoints for production
- Stop ECS service when not in use:
aws ecs update-service --cluster documind-cluster --service documind-api --desired-count 0 - Use Fargate Spot for non-production workloads
When redeploying in the future:
- AWS CLI configured (
aws configure) - Docker running
- CDK installed (
npm install -g aws-cdk) - Run
cd infra && npm install - Run
npx cdk bootstrap(if new account/region) - Run
npx cdk deploy - Configure OpenAI API key in Secrets Manager
- Restart ECS service
- Build and deploy frontend to S3
- Invalidate CloudFront cache
- Test application
All infrastructure is captured in code:
infra/
├── bin/infra.ts # CDK app entry point
├── lib/documind-stack.ts # All AWS resources defined here
├── package.json # CDK dependencies
├── tsconfig.json # TypeScript config
└── cdk.json # CDK config
backend/
├── Dockerfile # Container build instructions
├── pom.xml # Java dependencies
└── src/ # Application code
frontend/
├── package.json # Frontend dependencies
└── src/ # React application
No manual AWS console configuration is required - everything is Infrastructure as Code.