Overview
The backend API runs as a Docker container on AWS ECS Fargate behind an Application Load Balancer. This section covers building the Docker image, pushing to ECR, and deploying to ECS.Deployment Architecture
Build Docker Image
The backend uses a Python 3.11 slim base image with FastAPI and crawling dependencies.Review Dockerfile
Thebackend/Dockerfile contains:
The container exposes port 8000 for the FastAPI application.
Build the Image
Navigate to backend directory and build:Docker image built successfully! Image size should be around 500-700MB.
Test Image Locally (Optional)
Run container locally to verify
Run container locally to verify
Test the built image before pushing to ECR:Test the health endpoint:Stop the container with
Ctrl+C.Push Image to Amazon ECR
Get ECR Repository URL
Retrieve the ECR repository URL from Terraform:Authenticate Docker with ECR
Log in to ECR using AWS CLI:Tag Image for ECR
Tag the local image with the ECR repository URL:Push Image to ECR
Push the tagged image to ECR:Image successfully pushed to ECR!
Deploy to ECS
Force New Deployment
Trigger ECS to pull the new image and deploy:Monitor Deployment Progress
Watch the deployment status:Press
Ctrl+C to stop watching. Deployment typically takes 3-5 minutes.- Running count: Should increase from 0 to 1
- Desired count: Should be 1
- Status: Should be “PRIMARY”
Check Task Status
Verify the ECS task is running:If you see a task ARN, the container is running!
View Task Details
Get detailed task information:lastStatus: should be RUNNING.
Verify Deployment
Get Load Balancer URL
Test Health Endpoint
Wait 30-60 seconds for the ALB health check to pass, then test:Backend API is live and healthy!
Test WebSocket Endpoint
Test WebSocket connection (optional)
Test WebSocket connection (optional)
Install Test crawl endpoint:You should see streaming crawl progress messages.
websocat for WebSocket testing:View Container Logs
Via AWS CLI
View recent application logs:Via AWS Console
- Go to CloudWatch Console
- Navigate to Logs → Log groups
- Open
/ecs/llmstxt-api - View log streams (one per task/container)
Check for Errors
Search logs for error messages:Updating the Application
To deploy code changes:1
Make Code Changes
Edit backend code in
backend/ directory.2
Rebuild Docker Image
3
Tag and Push to ECR
4
Force ECS Deployment
5
Monitor Deployment
Watch deployment progress and verify health endpoint.
ECS performs a rolling deployment: new task starts before old task stops (zero downtime).
Troubleshooting
Task fails to start
Task fails to start
Check task stopped reason:Common issues:
- Image pull error: Verify ECR authentication
- Task execution role: Check IAM permissions
- Environment variables: Verify Terraform configuration
Health check failing
Health check failing
Check ALB target health:If unhealthy:
- Verify container is listening on port 8000
- Check security group allows ALB → ECS traffic
- Review container logs for startup errors
Cannot access ALB
Cannot access ALB
Verify security group:Ensure port 80 and 443 are open to 0.0.0.0/0.
Out of memory errors
Out of memory errors
Increase task memory:Edit Apply changes:
terraform/ecs.tf:Scaling Configuration
Manual Scaling
Increase the number of running tasks:Auto Scaling (Optional)
Configure ECS Auto Scaling based on CPU
Configure ECS Auto Scaling based on CPU
Add to Apply with
terraform/ecs.tf:terraform apply.Next Steps
Frontend Deployment
Deploy the Next.js frontend to Vercel