▸ Understanding Access Logs
Access logs provide a detailed record of every request passing through your API Gateway proxy. They are essential for:
-
✓
Security Analysis - Detect unusual patterns and potential threats
-
✓
Performance Monitoring - Identify slow endpoints and optimization opportunities
-
✓
Compliance Auditing - Meet regulatory requirements for data retention
-
✓
Troubleshooting - Debug issues with detailed request/response data
⚙ Log Configuration
proxy:
access_log:
enabled: true
format: "json"
fields:
- timestamp
- request_id
- client_ip
- method
- path
- status_code
- response_time
- request_size
- response_size
filters:
exclude_health_checks: true
sample_rate: 1.0
destination:
type: "cloudwatch"
stream_name: "api-gateway-logs"
💡 Pro Tip
Enable sampling for high-traffic APIs to reduce storage costs while maintaining statistical accuracy. A 10% sample rate is usually sufficient for trend analysis.
📈 Log Analysis Patterns
Here are common access log queries for API monitoring:
SELECT path, COUNT(*) as requests
FROM access_logs
WHERE timestamp > now() - interval '24 hours'
GROUP BY path
ORDER BY requests DESC LIMIT 10;
SELECT path, AVG(response_time) as avg_time
FROM access_logs
GROUP BY path
ORDER BY avg_time DESC LIMIT 5;
SELECT status_code, COUNT(*) as count
FROM access_logs
WHERE status_code >= 400
GROUP BY status_code;