๐ก๏ธ WAF Setup for Bike4Mind API Protection
This directory contains scripts for setting up AWS WAF (Web Application Firewall) to protect your Bike4Mind application from API hammering and enable emergency IP blocking.
๐จ Emergency Protection Featuresโ
- Rate Limiting: 1000 requests per 5 minutes per IP
- Emergency IP Blocking: Instantly block malicious IPs
- CloudWatch Monitoring: Track blocked requests and metrics
- Emergency Commands: Quick scripts for threat response
๐ Prerequisitesโ
- AWS CLI configured with appropriate permissions
- CloudFront distribution already deployed (via SST)
- Admin access to AWS WAF and CloudFront
๐ Setup Instructionsโ
Step 1: Find Your CloudFront Distribution IDโ
# Run the helper script to find your distribution ID
./get-cloudfront-id.sh
This will either automatically find your distribution ID or list all distributions for you to choose from.
Step 2: Deploy WAF Protectionโ
# Replace DISTRIBUTION_ID with your actual CloudFront distribution ID
./setup-waf.sh E1234567890ABC
What this creates:
- โ WAF Web ACL with rate limiting (1000 req/5min per IP)
- โ IP Set for emergency blocking
- โ CloudWatch metrics and monitoring
- โ Association with your CloudFront distribution
Step 3: Configure Emergency Commandsโ
After WAF setup completes, it will output commands like:
โ
IP Set created: 12345678-1234-1234-1234-123456789012
Update the emergency script:
- Edit
emergency-waf-commands.sh
- Replace
REPLACE_WITH_ACTUAL_IP_SET_ID
with your actual IP Set ID - Save the file
๐จ Emergency Response Commandsโ
Block an IP Addressโ
./emergency-waf-commands.sh block 192.168.1.100
Block an Entire Subnetโ
./emergency-waf-commands.sh block-subnet 10.0.0.0/8
Emergency Reset (Unblock All)โ
./emergency-waf-commands.sh unblock-all
List Currently Blocked IPsโ
./emergency-waf-commands.sh list
View WAF Metricsโ
# Last 1 hour (default)
./emergency-waf-commands.sh metrics
# Last 24 hours
./emergency-waf-commands.sh metrics 24
๐ Monitoringโ
CloudWatch Metricsโ
The WAF automatically sends metrics to CloudWatch:
- Namespace:
AWS/WAFV2
- Metrics:
BlockedRequests
,AllowedRequests
- Dimensions: WebACL, Rule
View in AWS Consoleโ
- Go to AWS CloudWatch โ Metrics
- Select "WAFV2" namespace
- View metrics for your Web ACL
๐ง Manual Commands (Reference)โ
If you need to run WAF commands manually:
Get Current Blocked IPsโ
aws wafv2 get-ip-set \
--scope CLOUDFRONT \
--id YOUR_IP_SET_ID \
--region us-east-1
Block an IPโ
aws wafv2 update-ip-set \
--scope CLOUDFRONT \
--id YOUR_IP_SET_ID \
--addresses "192.168.1.100/32" "10.0.0.0/8" \
--region us-east-1
View WAF Rulesโ
aws wafv2 get-web-acl \
--scope CLOUDFRONT \
--id YOUR_WEB_ACL_ID \
--region us-east-1