Skip to main content

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

The backend/Dockerfile contains:
The container exposes port 8000 for the FastAPI application.

Build the Image

Navigate to backend directory and build:
Expected output:
Docker image built successfully! Image size should be around 500-700MB.

Test Image Locally (Optional)

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:
Example output:
Save this as an environment variable:

Authenticate Docker with ECR

Log in to ECR using AWS CLI:
Expected output:
ECR authentication tokens expire after 12 hours. Re-run this command if you get authentication errors.

Tag Image for ECR

Tag the local image with the ECR repository URL:
Verify the tag:
You should see both tags:

Push Image to ECR

Push the tagged image to ECR:
Expected output:
This takes 2-5 minutes depending on your internet connection.
Image successfully pushed to ECR!

Deploy to ECS

Force New Deployment

Trigger ECS to pull the new image and deploy:
Expected output:

Monitor Deployment Progress

Watch the deployment status:
Press Ctrl+C to stop watching. Deployment typically takes 3-5 minutes.
Look for:
  • 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:
Expected output:
If you see a task ARN, the container is running!

View Task Details

Get detailed task information:
Check lastStatus: should be RUNNING.

Verify Deployment

Get Load Balancer URL

Example output:

Test Health Endpoint

Wait 30-60 seconds for the ALB health check to pass, then test:
Expected response:
Backend API is live and healthy!

Test WebSocket Endpoint

Install websocat for WebSocket testing:
Test crawl endpoint:
You should see streaming crawl progress messages.

View Container Logs

Via AWS CLI

View recent application logs:

Via AWS Console

  1. Go to CloudWatch Console
  2. Navigate to LogsLog groups
  3. Open /ecs/llmstxt-api
  4. 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

Check task stopped reason:
Common issues:
  • Image pull error: Verify ECR authentication
  • Task execution role: Check IAM permissions
  • Environment variables: Verify Terraform configuration
Check ALB target health:
If unhealthy:
  1. Verify container is listening on port 8000
  2. Check security group allows ALB → ECS traffic
  3. Review container logs for startup errors
Verify security group:
Ensure port 80 and 443 are open to 0.0.0.0/0.
Increase task memory:Edit terraform/ecs.tf:
Apply changes:

Scaling Configuration

Manual Scaling

Increase the number of running tasks:

Auto Scaling (Optional)

Add to terraform/ecs.tf:
Apply with terraform apply.

Next Steps

Frontend Deployment

Deploy the Next.js frontend to Vercel