-
Docker Desktop installed and running
-
AWS CLI installed ✅ (Already installed)
aws --version
-
AWS Account with credentials configured
aws configure
You'll need:
- AWS Access Key ID
- AWS Secret Access Key
- Default region (e.g., us-east-1)
- Output format: json
-
Environment Variables (from .env file)
- GROQ_API_KEY
- MONGODB_URI
cd backend
./deploy-lambda.ps1cd backend
chmod +x deploy-lambda.sh
./deploy-lambda.sh- ✅ Creates ECR (Elastic Container Registry) repository
- ✅ Authenticates Docker with AWS
- ✅ Builds Docker image with optimizations
- ✅ Pushes image to ECR
- ✅ Creates IAM role for Lambda
- ✅ Creates/Updates Lambda function
- ✅ Sets up Function URL (no API Gateway needed!)
- ✅ Configures CORS for frontend
You'll get a Function URL like:
https://xxxxxxxxxxxxxx.lambda-url.us-east-1.on.aws/
# Health check
curl https://your-function-url.lambda-url.us-east-1.on.aws/api/health
# Root endpoint
curl https://your-function-url.lambda-url.us-east-1.on.aws/-
Open
frontend/.envor create it:VITE_API_URL=https://your-function-url.lambda-url.us-east-1.on.aws
-
Rebuild frontend:
cd frontend npm run build
AWS Lambda Free Tier includes:
- 1M requests per month - FREE
- 400,000 GB-seconds of compute time - FREE
Your configuration:
- Memory: 2048 MB (2 GB)
- Timeout: 900 seconds (15 min)
- Free tier gives: 400,000 / 2 = 200,000 seconds = ~55 hours of execution time
Estimated free usage:
- ~2,200 requests/month at 900s each = FREE
- Or ~220,000 requests at 90s each = FREE
After free tier: ~$0.0000166667 per GB-second
- Docker image: 10 GB (should be fine)
- Unzipped: 250 MB (might be tight with ML models)
- Ephemeral storage: 512 MB - 10 GB
- First request after idle: 5-10 seconds
- Container image cold start: slower than ZIP
- Set to 2048 MB (2 GB) for ML models
- Increase if OOM errors occur
Error: docker: command not found
Fix: Install Docker Desktop and ensure it's running
Error: Unable to locate credentials
Fix:
aws configure
# Enter your AWS Access Key ID and SecretError: RequestEntityTooLargeException
Fix: The sentence-transformers model might be too heavy. Consider:
- Using Groq embeddings API instead
- Switching to a smaller model
- Using ECS/Fargate instead of Lambda
Error: Task timed out after 900.00 seconds
Fix: Increase timeout (max 15 min) or optimize code
Error: Runtime exited with error: signal: killed
Fix: Increase memory in script (currently 2048 MB, max 10240 MB)
To update after code changes:
cd backend
./deploy-lambda.ps1 # or ./deploy-lambda.shThe script will:
- Rebuild Docker image
- Push new version to ECR
- Update Lambda function automatically
To remove all AWS resources:
# Delete Lambda function
aws lambda delete-function --function-name rag-backend-api --region us-east-1
# Delete ECR repository
aws ecr delete-repository --repository-name rag-backend --force --region us-east-1
# Delete IAM role (detach policies first)
aws iam detach-role-policy --role-name rag-lambda-execution-role --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
aws iam delete-role --role-name rag-lambda-execution-roleIf the Docker image is too large or cold starts are problematic, use ECS:
# Will create separate ECS deployment script if neededcd frontend
npm install -g vercel
vercelcd frontend
npm run build
npm install -g netlify-cli
netlify deployView logs in AWS CloudWatch:
aws logs tail /aws/lambda/rag-backend-api --follow --region us-east-1Or in AWS Console: CloudWatch → Log groups → /aws/lambda/rag-backend-api
If deployment fails, check:
- Docker is running
- AWS credentials are valid:
aws sts get-caller-identity - Region is correct (default: us-east-1)
- No firewall blocking Docker/AWS
Next Steps:
- Run deployment script
- Test the Function URL
- Update frontend with API URL
- Deploy frontend to Vercel
- Share your app! 🚀