AWS WAF blocks attacks before they hit your Lambda functions and cost you money. REST APIs only - HTTP APIs are on their own because AWS loves feature parity. We've seen production systems get hammered by 50K+ requests/minute of SQL injection attempts (mostly ' OR '1'='1
and UNION SELECT
garbage) until WAF was properly configured. That attack cost $4K in Lambda invocations before we realized what was happening.
Critical WAF rules that saved our ass:
- SQL Injection Protection - Catches
UNION SELECT
and similar garbage in query parameters - XSS Filter - Blocks
<script>
tags andjavascript:
attempts - Rate Limiting - 1000 requests per 5-minute window per IP (adjust for your traffic)
- Known Bad IPs - AWS managed rule set blocks Tor exit nodes and known botnets
- Size Restrictions - Reject requests over 1MB body size to prevent DoS attacks
WAF costs $1.00 per web ACL + $1.00 per rule + $0.60 per million requests. Sounds expensive until a single DDoS attack costs you $10K in API Gateway charges in one afternoon. Set up CloudWatch alarms for blocked request spikes - we learned this the hard way when 90% of our traffic was attack attempts and we didn't notice until the AWS bill arrived. "AllowedRequests" dropping below 50% of total requests is a good threshold for alarm.
Resource Policies (VPC and IP Whitelisting)
Resource policies are your kill switch. Lock down admin APIs to specific VPCs or IP ranges. That "internal only" API shouldn't be accessible from random coffee shop WiFi.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:*:*:*",
"Condition": {
"IpAddress": {
"aws:SourceIp": ["203.0.113.0/24", "198.51.100.0/24"]
}
}
}
]
}
Warning: This policy blocks everything except those IP ranges - test it thoroughly on a dev stage before deploying or you'll lock yourself out. I've seen engineers deploy this on prod, then panic when they can't access the API from home.
VPC endpoint restrictions work great for internal microservices. Private APIs never touch the internet - traffic stays within your VPC. Perfect for backend services that shouldn't be publicly accessible.
TLS Configuration That Doesn't Suck
API Gateway only supports TLS 1.2+ by default, which is good. But custom domain certificates require ACM certificates - don't upload your own certs, that's amateur hour.
Certificate pinning is possible but painful with CloudFront distribution changes. We've had clients implement it for high-security APIs, but expect mobile apps to break when certificates rotate. HSTS headers are easier and catch most downgrade attacks.
Edge-optimized endpoints terminate TLS at CloudFront edge locations, then re-encrypt to API Gateway. Regional endpoints terminate TLS once at the API Gateway service. Both are secure, but edge-optimized adds complexity and potential attack surface. Pick regional unless you actually need global performance.