Serverless AI-powered log analysis tool using Claude API and AWS infrastructure.
This project automatically analyzes application logs using Claude AI (Anthropic) and provides:
- Summary of issues found
- Severity classification (critical/warning/info)
- Recommended actions
Built with AWS Lambda, API Gateway, and deployed via Terraform (Infrastructure as Code).
User Request (HTTP POST)
|
v
API Gateway
|
v
AWS Lambda (Python 3.12)
|
v
Claude API (Anthropic)
|
v
JSON Response (AI Analysis)
- Cloud: AWS (Lambda, API Gateway, IAM)
- AI: Claude Sonnet 4 (Anthropic)
- Language: Python 3.12
- IaC: Terraform
- Libraries: anthropic, boto3
ai-log-analyzer/
├── lambda/
│ ├── lambda_function.py # Main Lambda handler
│ └── (anthropic libraries)
├── terraform/
│ ├── main.tf # Infrastructure definition
│ ├── variables.tf # Configuration variables
│ ├── outputs.tf # API endpoint outputs
│ └── terraform.tfvars # Variable values (not in repo)
└── README.md
- AWS Account with CLI configured
- Terraform >= 1.0
- Anthropic API key
- Clone repository
git clone https://github.com/marand85/ai-log-analyzer
cd ai-log-analyzer- Configure variables
cd terraform
cp terraform.tfvars.example terraform.tfvarsEdit terraform.tfvars with your Anthropic API key (use your preferred editor):
nano terraform.tfvars
# or: code terraform.tfvars
# or: vim terraform.tfvars- Deploy infrastructure
terraform init
terraform apply- Get API endpoint
terraform output api_endpointcurl -X POST https://your-api-endpoint/ai-log-analyzer \
-H "Content-Type: application/json" \
-d '{"logs": "ERROR 2025-01-16 12:00:00 Database connection timeout\nCRITICAL Payment processing failed"}'{
"status": "success",
"analysis": "## Log Analysis Report\n\n### Summary\n- Database timeout\n- Payment failure\n\n### Severity: CRITICAL\n\n### Recommended Actions\n- Check database connectivity\n- Review payment gateway status..."
}
Always remember to destroy your infrastructure when you are done testing to avoid unexpected AWS charges:
terraform destroy- Serverless - No infrastructure management
- AI-Powered - Claude Sonnet 4 for intelligent analysis
- Infrastructure as Code - Full Terraform deployment
- Scalable - Auto-scaling Lambda + API Gateway
- Cost-Effective - Pay only for actual usage
Package Lambda dependencies:
cd lambda
pip install anthropic -t .Update code (use your preferred editor):
nano lambda_function.py
# or: code lambda_function.py
# or: vim lambda_function.pyRedeploy:
cd ../terraform
terraform apply- API key stored as encrypted environment variable
- IAM roles with least privilege access
- HTTPS-only API endpoint
- No authentication on API (add API Gateway authorizer for production)
| Service | Usage | Cost |
|---|---|---|
| Lambda | 1000 requests/month | ~$0.20 |
| API Gateway | 1000 requests/month | ~$0.01 |
| Claude API | 1000 requests | ~$3.00 |
| Total | ~$3.21/month |
Based on Free Tier + typical usage
- Add authentication (API Gateway Authorizer)
- Store analysis results in DynamoDB
- Add CloudWatch dashboards
- Support multiple AI models (GPT-4, etc.)
- Batch log processing
Mariusz Andrzejewski AI Platform Engineer
MIT License