Infrastructure Overview
The llms.txt Generator infrastructure is fully defined as code using Terraform and deployed on AWS. The architecture is designed for high availability, scalability, and cost-effectiveness.Infrastructure Diagram
Core Components
1. ECS Fargate Cluster
Container Orchestration
Purpose: Runs the FastAPI backend application in Docker containersConfiguration:
- Launch Type: Fargate (serverless)
- Task CPU: 512 units (0.5 vCPU)
- Task Memory: 1024 MB (1 GB)
- Container Port: 8000
- Desired Count: 1 task
- Network Mode:
awsvpc
- Container Insights: Enabled for enhanced monitoring
- Auto-scaling: Can scale based on CPU/memory metrics
- Health Checks: ALB performs health checks on
/healthendpoint - Zero Downtime Deployments: Rolling updates when new images are pushed
2. Application Load Balancer (ALB)
Load Balancing & SSL Termination
Purpose: Distributes HTTP/HTTPS traffic to ECS tasksConfiguration:
- Type: Application Load Balancer
- Scheme: Internet-facing
- Listeners: HTTP (80), HTTPS (443)
- Target Type: IP (required for Fargate)
- Health Check Path:
/health
HTTP Listener (Port 80)
HTTP Listener (Port 80)
- Forwards traffic to target group
- Can be configured to redirect to HTTPS
- Used for health checks
HTTPS Listener (Port 443)
HTTPS Listener (Port 443)
- SSL/TLS termination using ACM certificate
- Forwards decrypted traffic to backend
- Security Policy:
ELBSecurityPolicy-2016-08 - Supports WebSocket (WSS) connections
3. ECR (Elastic Container Registry)
Docker Image Registry
Purpose: Stores and manages Docker images for the FastAPI backendFeatures:
- Image vulnerability scanning on push
- Mutable image tags (allows
:latestupdates) - Private repository with IAM-based access
- Integrated with ECS for seamless deployments
4. Lambda Function
Scheduled Recrawl Executor
Purpose: Triggers automated recrawls of enrolled sitesConfiguration:
- Runtime: Python 3.11
- Timeout: 600 seconds (10 minutes)
- Memory: 512 MB
- Trigger: EventBridge cron schedule
- Handler:
lambda_handler.lambda_handler
- EventBridge triggers Lambda every 6 hours
- Lambda sends HTTP POST to
/internal/cron/recrawl - Backend processes recrawl in background task
- Lambda completes quickly, backend handles async work
The Lambda function deployment package is built using
backend/deployment/build_lambda.sh and includes all Python dependencies (~70MB).5. EventBridge Rule
Cron Scheduler
Purpose: Triggers Lambda function on a scheduleSchedule Expression:
cron(0 */6 * * ? *)Frequency: Every 6 hours (00:00, 06:00, 12:00, 18:00 UTC)6. Security Groups
ALB Security Group
Ingress:
- Port 80 from
0.0.0.0/0 - Port 443 from
0.0.0.0/0
- All traffic to
0.0.0.0/0
ECS Tasks Security Group
Ingress:
- Port 8000 from ALB security group only
- All traffic to
0.0.0.0/0(for external API calls)
7. IAM Roles
ECS Execution Role
ECS Execution Role
Purpose: Allows ECS to pull images from ECR and write logs to CloudWatchManaged Policies:
AmazonECSTaskExecutionRolePolicy
- Pull images from ECR
- Create and write CloudWatch log streams
ECS Task Role
ECS Task Role
Purpose: Grants permissions to the running containerCustom Permissions:
- CloudWatch Logs write access
- Can be extended for S3, Secrets Manager, etc.
Lambda Execution Role
Lambda Execution Role
Purpose: Allows Lambda to execute and write logsManaged Policies:
AWSLambdaBasicExecutionRole
- CloudWatch Logs write access
8. CloudWatch Log Groups
ECS Logs
Log Group:
/ecs/llmstxt-apiRetention: 14 daysContents: Application logs, errors, crawl activityLambda Logs
Log Group:
/aws/lambda/llmstxt-auto-updateRetention: 14 daysContents: Scheduled recrawl execution logs9. S3 Bucket (Lambda Deployments)
Lambda Package Storage
Purpose: Stores Lambda deployment package (.zip)Bucket Name:
llmstxt-lambda-deployments-<account-id>Objects:lambda-deployment.zip(~70MB with dependencies)
Network Architecture
VPC Configuration
The infrastructure uses your default VPC or a specified VPC with at least 2 subnets in different availability zones for high availability.
- VPC: Must have internet gateway for public access
- Subnets: Minimum 2 subnets in different AZs
- Route Tables: Subnets must route to internet gateway
- Public IPs: ECS tasks require public IPs for external API calls
Terraform State Management
Recommended Backend Configuration:Cost Optimization
ECS Fargate
Current: 0.5 vCPU, 1 GB RAMCost: ~$12-15/month (1 task running 24/7)Optimization: Scale to zero during off-hours if possible
Lambda
Invocations: 4 per day (every 6 hours)Cost: Less than $1/month (free tier covers this)Optimization: Already optimized with fast execution
CloudWatch Logs
Retention: 14 daysCost: ~$1-3/month (depends on log volume)Optimization: Reduce retention or export to S3
ALB
Cost: ~$16-20/month (base + LCU charges)Optimization: Consider CloudFront for caching
Monitoring & Alerts
CloudWatch Alarms
Key Metrics to Monitor
- ECS CPU Utilization: Should stay below 80%
- ECS Memory Utilization: Should stay below 80%
- ALB Target Response Time: Should be < 1 second
- ALB Healthy Host Count: Should match desired count
- Lambda Errors: Should be zero
- Lambda Duration: Should be < 60 seconds
Next Steps
Data Flow
Understand how requests flow through the infrastructure
Deployment Guide
Step-by-step deployment instructions