[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7AB8FV8BH0TWCGA6K2QY6F9":3,"skill-same:01M7AB8FV8BH0TWCGA6K2QY6F9":85},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":16,"sourceHtmlUrl":17,"categories":18,"keywords":19,"publishedAt":20,"linkOnly":21,"markdownContent":22,"markdownBody":23,"frontMatter":24,"refName":48,"commitSha":49,"skillDirectory":50,"forksCount":14,"repositoryHtmlUrl":51,"repositoryHomepageUrl":6,"ownerHtmlUrl":52,"ownerBlogUrl":6,"ownerDescription":53,"updatedAt":54,"install":55,"resources":68},"01M7AB8FV8BH0TWCGA6K2QY6F9","securing-api-gateway-with-aws-waf",null,"Secures AWS API Gateway endpoints with AWS WAF by configuring managed rule groups for OWASP Top 10 protection, custom rate-limiting rules, bot control, IP reputation filtering, and WAF metric monitoring. Use when deploying API Gateway endpoints that need protection against common web attacks, or when implementing rate limiting and throttling to prevent API abuse and DDoS.","NeelakshSaxena\u002FVayu","NeelakshSaxena","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F87892838?v=4","01M7A3B9YFS6F6N9DD1787DT86","Neelaksh Saxena","01M7A3B9ZKBT09MNMPX2XN69BY",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fsecuring-api-gateway-with-aws-waf\u002FLICENSE","https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fsecuring-api-gateway-with-aws-waf\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: securing-api-gateway-with-aws-waf\ndescription: 'Secures AWS API Gateway endpoints with AWS WAF by configuring managed\n  rule groups for OWASP Top 10 protection, custom rate-limiting rules, bot control,\n  IP reputation filtering, and WAF metric monitoring. Use when deploying API Gateway\n  endpoints that need protection against common web attacks, or when implementing\n  rate limiting and throttling to prevent API abuse and DDoS.\n\n  '\ndomain: cybersecurity\nsubdomain: cloud-security\ntags:\n- cloud-security\n- aws\n- waf\n- api-gateway\n- rate-limiting\n- bot-protection\n- owasp\nversion: '1.0'\nauthor: mahipal\nlicense: Apache-2.0\nnist_csf:\n- PR.IR-01\n- ID.AM-08\n- GV.SC-06\n- DE.CM-01\nmitre_attack:\n- T1078.004\n- T1530\n- T1537\n- T1580\n- T0816\n---\n\n# Securing API Gateway with AWS WAF\n\n## When to Use\n\n- When deploying API Gateway endpoints that require protection against common web attacks\n- When implementing rate limiting and throttling to prevent API abuse and DDoS attacks\n- When building bot detection and mitigation for API endpoints exposed to the internet\n- When compliance requires WAF protection for all public-facing API endpoints\n- When customizing access controls based on IP reputation, geolocation, or request patterns\n\n**Do not use** for network-level DDoS protection (use AWS Shield), for application logic vulnerabilities (use SAST\u002FDAST tools), or for internal API security between microservices (use service mesh authentication and authorization).\n\n## Prerequisites\n\n- AWS API Gateway (REST or HTTP API) deployed with public endpoints\n- IAM permissions for `wafv2:*` and `apigateway:*` operations\n- CloudWatch and S3 or Kinesis Firehose configured for WAF logging\n- Understanding of the API's expected traffic patterns for rate limiting configuration\n- IP reputation lists or threat intelligence feeds for custom IP blocking\n\n## Workflow\n\n### Step 1: Create a WAF Web ACL with Managed Rule Groups\n\nCreate a Web ACL with AWS Managed Rules for baseline protection against OWASP Top 10 attacks.\n\n```bash\n# Create a WAF Web ACL with managed rule groups\naws wafv2 create-web-acl \\\n  --name api-gateway-waf \\\n  --scope REGIONAL \\\n  --default-action '{\"Allow\":{}}' \\\n  --visibility-config '{\n    \"SampledRequestsEnabled\": true,\n    \"CloudWatchMetricsEnabled\": true,\n    \"MetricName\": \"api-gateway-waf\"\n  }' \\\n  --rules '[\n    {\n      \"Name\": \"AWSManagedRulesCommonRuleSet\",\n      \"Priority\": 1,\n      \"Statement\": {\n        \"ManagedRuleGroupStatement\": {\n          \"VendorName\": \"AWS\",\n          \"Name\": \"AWSManagedRulesCommonRuleSet\"\n        }\n      },\n      \"OverrideAction\": {\"None\": {}},\n      \"VisibilityConfig\": {\n        \"SampledRequestsEnabled\": true,\n        \"CloudWatchMetricsEnabled\": true,\n        \"MetricName\": \"CommonRuleSet\"\n      }\n    },\n    {\n      \"Name\": \"AWSManagedRulesKnownBadInputsRuleSet\",\n      \"Priority\": 2,\n      \"Statement\": {\n        \"ManagedRuleGroupStatement\": {\n          \"VendorName\": \"AWS\",\n          \"Name\": \"AWSManagedRulesKnownBadInputsRuleSet\"\n        }\n      },\n      \"OverrideAction\": {\"None\": {}},\n      \"VisibilityConfig\": {\n        \"SampledRequestsEnabled\": true,\n        \"CloudWatchMetricsEnabled\": true,\n        \"MetricName\": \"KnownBadInputs\"\n      }\n    },\n    {\n      \"Name\": \"AWSManagedRulesSQLiRuleSet\",\n      \"Priority\": 3,\n      \"Statement\": {\n        \"ManagedRuleGroupStatement\": {\n          \"VendorName\": \"AWS\",\n          \"Name\": \"AWSManagedRulesSQLiRuleSet\"\n        }\n      },\n      \"OverrideAction\": {\"None\": {}},\n      \"VisibilityConfig\": {\n        \"SampledRequestsEnabled\": true,\n        \"CloudWatchMetricsEnabled\": true,\n        \"MetricName\": \"SQLiRuleSet\"\n      }\n    },\n    {\n      \"Name\": \"AWSManagedRulesAmazonIpReputationList\",\n      \"Priority\": 4,\n      \"Statement\": {\n        \"ManagedRuleGroupStatement\": {\n          \"VendorName\": \"AWS\",\n          \"Name\": \"AWSManagedRulesAmazonIpReputationList\"\n        }\n      },\n      \"OverrideAction\": {\"None\": {}},\n      \"VisibilityConfig\": {\n        \"SampledRequestsEnabled\": true,\n        \"CloudWatchMetricsEnabled\": true,\n        \"MetricName\": \"IPReputationList\"\n      }\n    }\n  ]'\n```\n\n### Step 2: Add Rate Limiting Rules\n\nConfigure rate-based rules to throttle excessive API requests per IP address.\n\n```bash\n# Get the Web ACL ARN and lock token\nWEB_ACL_ARN=$(aws wafv2 list-web-acls --scope REGIONAL \\\n  --query \"WebACLs[?Name=='api-gateway-waf'].ARN\" --output text)\n\n# Update Web ACL to add rate limiting rule\naws wafv2 update-web-acl \\\n  --name api-gateway-waf \\\n  --scope REGIONAL \\\n  --id $(aws wafv2 list-web-acls --scope REGIONAL --query \"WebACLs[?Name=='api-gateway-waf'].Id\" --output text) \\\n  --lock-token $(aws wafv2 get-web-acl --name api-gateway-waf --scope REGIONAL --id WEB_ACL_ID --query 'LockToken' --output text) \\\n  --default-action '{\"Allow\":{}}' \\\n  --visibility-config '{\n    \"SampledRequestsEnabled\": true,\n    \"CloudWatchMetricsEnabled\": true,\n    \"MetricName\": \"api-gateway-waf\"\n  }' \\\n  --rules '[\n    {\n      \"Name\": \"RateLimitPerIP\",\n      \"Priority\": 0,\n      \"Statement\": {\n        \"RateBasedStatement\": {\n          \"Limit\": 2000,\n          \"AggregateKeyType\": \"IP\"\n        }\n      },\n      \"Action\": {\"Block\": {}},\n      \"VisibilityConfig\": {\n        \"SampledRequestsEnabled\": true,\n        \"CloudWatchMetricsEnabled\": true,\n        \"MetricName\": \"RateLimitPerIP\"\n      }\n    },\n    {\n      \"Name\": \"RateLimitLoginEndpoint\",\n      \"Priority\": 5,\n      \"Statement\": {\n        \"RateBasedStatement\": {\n          \"Limit\": 100,\n          \"AggregateKeyType\": \"IP\",\n          \"ScopeDownStatement\": {\n            \"ByteMatchStatement\": {\n              \"FieldToMatch\": {\"UriPath\": {}},\n              \"PositionalConstraint\": \"STARTS_WITH\",\n              \"SearchString\": \"\u002Fapi\u002Fauth\u002Flogin\",\n              \"TextTransformations\": [{\"Priority\": 0, \"Type\": \"LOWERCASE\"}]\n            }\n          }\n        }\n      },\n      \"Action\": {\"Block\": {}},\n      \"VisibilityConfig\": {\n        \"SampledRequestsEnabled\": true,\n        \"CloudWatchMetricsEnabled\": true,\n        \"MetricName\": \"RateLimitLogin\"\n      }\n    }\n  ]'\n```\n\n### Step 3: Implement Bot Control\n\nAdd AWS WAF Bot Control to detect and manage automated traffic.\n\n```bash\n# Add Bot Control managed rule group\n# (Add to the rules array when updating the Web ACL)\n{\n  \"Name\": \"AWSManagedRulesBotControlRuleSet\",\n  \"Priority\": 6,\n  \"Statement\": {\n    \"ManagedRuleGroupStatement\": {\n      \"VendorName\": \"AWS\",\n      \"Name\": \"AWSManagedRulesBotControlRuleSet\",\n      \"ManagedRuleGroupConfigs\": [{\n        \"AWSManagedRulesBotControlRuleSet\": {\n          \"InspectionLevel\": \"COMMON\"\n        }\n      }],\n      \"ExcludedRules\": [\n        {\"Name\": \"CategoryHttpLibrary\"},\n        {\"Name\": \"SignalNonBrowserUserAgent\"}\n      ]\n    }\n  },\n  \"OverrideAction\": {\"None\": {}},\n  \"VisibilityConfig\": {\n    \"SampledRequestsEnabled\": true,\n    \"CloudWatchMetricsEnabled\": true,\n    \"MetricName\": \"BotControl\"\n  }\n}\n```\n\n### Step 4: Create Custom Rules for API-Specific Protection\n\nBuild custom WAF rules for API-specific security requirements.\n\n```bash\n# Block requests without required API key header\n{\n  \"Name\": \"RequireAPIKey\",\n  \"Priority\": 7,\n  \"Statement\": {\n    \"NotStatement\": {\n      \"Statement\": {\n        \"ByteMatchStatement\": {\n          \"FieldToMatch\": {\n            \"SingleHeader\": {\"Name\": \"x-api-key\"}\n          },\n          \"PositionalConstraint\": \"EXACTLY\",\n          \"SearchString\": \"\",\n          \"TextTransformations\": [{\"Priority\": 0, \"Type\": \"NONE\"}]\n        }\n      }\n    }\n  },\n  \"Action\": {\"Block\": {\"CustomResponse\": {\"ResponseCode\": 403}}},\n  \"VisibilityConfig\": {\n    \"SampledRequestsEnabled\": true,\n    \"CloudWatchMetricsEnabled\": true,\n    \"MetricName\": \"RequireAPIKey\"\n  }\n}\n\n# Geo-restrict to allowed countries\n{\n  \"Name\": \"GeoRestriction\",\n  \"Priority\": 8,\n  \"Statement\": {\n    \"NotStatement\": {\n      \"Statement\": {\n        \"GeoMatchStatement\": {\n          \"CountryCodes\": [\"US\", \"CA\", \"GB\", \"DE\", \"FR\", \"AU\"]\n        }\n      }\n    }\n  },\n  \"Action\": {\"Block\": {}},\n  \"VisibilityConfig\": {\n    \"SampledRequestsEnabled\": true,\n    \"CloudWatchMetricsEnabled\": true,\n    \"MetricName\": \"GeoRestriction\"\n  }\n}\n\n# Block oversized request bodies (prevent payload attacks)\n{\n  \"Name\": \"MaxBodySize\",\n  \"Priority\": 9,\n  \"Statement\": {\n    \"SizeConstraintStatement\": {\n      \"FieldToMatch\": {\"Body\": {\"OversizeHandling\": \"MATCH\"}},\n      \"ComparisonOperator\": \"GT\",\n      \"Size\": 10240,\n      \"TextTransformations\": [{\"Priority\": 0, \"Type\": \"NONE\"}]\n    }\n  },\n  \"Action\": {\"Block\": {}},\n  \"VisibilityConfig\": {\n    \"SampledRequestsEnabled\": true,\n    \"CloudWatchMetricsEnabled\": true,\n    \"MetricName\": \"MaxBodySize\"\n  }\n}\n```\n\n### Step 5: Associate WAF with API Gateway and Enable Logging\n\nAttach the Web ACL to the API Gateway stage and configure comprehensive logging.\n\n```bash\n# Associate Web ACL with API Gateway\naws wafv2 associate-web-acl \\\n  --web-acl-arn $WEB_ACL_ARN \\\n  --resource-arn arn:aws:apigateway:us-east-1::\u002Frestapis\u002FAPI_ID\u002Fstages\u002Fprod\n\n# Enable WAF logging to S3 via Kinesis Firehose\naws wafv2 put-logging-configuration \\\n  --logging-configuration '{\n    \"ResourceArn\": \"'$WEB_ACL_ARN'\",\n    \"LogDestinationConfigs\": [\n      \"arn:aws:firehose:us-east-1:ACCOUNT:deliverystream\u002Faws-waf-logs-api-gateway\"\n    ],\n    \"RedactedFields\": [\n      {\"SingleHeader\": {\"Name\": \"authorization\"}},\n      {\"SingleHeader\": {\"Name\": \"cookie\"}}\n    ]\n  }'\n\n# Verify association\naws wafv2 get-web-acl-for-resource \\\n  --resource-arn arn:aws:apigateway:us-east-1::\u002Frestapis\u002FAPI_ID\u002Fstages\u002Fprod\n```\n\n### Step 6: Monitor WAF Metrics and Tune Rules\n\nMonitor WAF effectiveness and tune rules to reduce false positives.\n\n```bash\n# Get WAF metrics from CloudWatch\naws cloudwatch get-metric-statistics \\\n  --namespace AWS\u002FWAFV2 \\\n  --metric-name BlockedRequests \\\n  --dimensions Name=WebACL,Value=api-gateway-waf Name=Rule,Value=ALL \\\n  --start-time 2026-02-22T00:00:00Z \\\n  --end-time 2026-02-23T00:00:00Z \\\n  --period 3600 \\\n  --statistics Sum\n\n# Get sampled requests for a specific rule\naws wafv2 get-sampled-requests \\\n  --web-acl-arn $WEB_ACL_ARN \\\n  --rule-metric-name RateLimitPerIP \\\n  --scope REGIONAL \\\n  --time-window '{\"StartTime\":\"2026-02-22T00:00:00Z\",\"EndTime\":\"2026-02-23T00:00:00Z\"}' \\\n  --max-items 50\n\n# Check rate-limited IPs\naws wafv2 get-rate-based-statement-managed-keys \\\n  --web-acl-name api-gateway-waf \\\n  --scope REGIONAL \\\n  --web-acl-id WEB_ACL_ID \\\n  --rule-name RateLimitPerIP\n\n# Create CloudWatch alarm for high block rate\naws cloudwatch put-metric-alarm \\\n  --alarm-name waf-high-block-rate \\\n  --namespace AWS\u002FWAFV2 \\\n  --metric-name BlockedRequests \\\n  --dimensions Name=WebACL,Value=api-gateway-waf Name=Rule,Value=ALL \\\n  --statistic Sum --period 300 --threshold 1000 \\\n  --comparison-operator GreaterThanThreshold \\\n  --evaluation-periods 2 \\\n  --alarm-actions arn:aws:sns:us-east-1:ACCOUNT:security-alerts\n```\n\n## Key Concepts\n\n| Term | Definition |\n|------|------------|\n| Web ACL | AWS WAF access control list that defines the collection of rules and their actions (allow, block, count) applied to associated resources |\n| Managed Rule Group | Pre-configured set of WAF rules maintained by AWS or third-party vendors for common attack patterns like OWASP Top 10 |\n| Rate-Based Rule | WAF rule that tracks request rates per IP address and blocks traffic exceeding a defined threshold within a 5-minute window |\n| Bot Control | AWS WAF managed rule group that identifies and manages automated traffic including scrapers, crawlers, and attack bots |\n| IP Reputation List | AWS-maintained list of IP addresses associated with malicious activity including botnets, scanners, and known attackers |\n| Custom Response | WAF capability to return specific HTTP status codes and custom response bodies when blocking requests |\n\n## Tools & Systems\n\n- **AWS WAF**: Web application firewall service for protecting API Gateway, ALB, CloudFront, and AppSync endpoints\n- **AWS Managed Rules**: Pre-built rule groups for common attack patterns maintained by AWS security team\n- **AWS Firewall Manager**: Central management of WAF policies across multiple accounts in AWS Organizations\n- **Kinesis Firehose**: Streaming delivery service for WAF logs to S3, Elasticsearch, or third-party analytics\n- **CloudWatch**: Monitoring service for WAF metrics including allowed, blocked, and counted requests\n\n## Common Scenarios\n\n### Scenario: Protecting a Public API from Credential Stuffing and Bot Attacks\n\n**Context**: A public REST API experiences thousands of authentication attempts per hour from automated bots attempting credential stuffing against the `\u002Fapi\u002Fauth\u002Flogin` endpoint.\n\n**Approach**:\n1. Create a Web ACL with AWS Managed Rules Common Rule Set for baseline protection\n2. Add a rate-based rule limiting the login endpoint to 100 requests per IP per 5 minutes\n3. Enable Bot Control managed rules to detect and block automated traffic\n4. Add IP Reputation List to block known malicious IPs proactively\n5. Create a custom rule blocking requests without proper User-Agent headers\n6. Enable WAF logging and create CloudWatch alarms for high block rates\n7. Review sampled blocked requests weekly to tune rules and reduce false positives\n\n**Pitfalls**: Rate limiting by IP can block legitimate users behind shared NAT gateways or corporate proxies. Consider using API key or authenticated session-based rate limiting for more granular control. Bot Control rules in COMMON inspection level may block legitimate API clients; start in Count mode and review before switching to Block.\n\n## Output Format\n\n```\nAWS WAF API Gateway Security Report\n======================================\nWeb ACL: api-gateway-waf\nAssociated Resource: API Gateway - production-api (prod stage)\nReport Period: 2026-02-16 to 2026-02-23\n\nTRAFFIC SUMMARY:\n  Total requests:              2,450,000\n  Allowed requests:            2,380,000 (97.1%)\n  Blocked requests:               70,000 (2.9%)\n\nBLOCKS BY RULE:\n  RateLimitPerIP:              28,000 (40%)\n  AWSManagedRulesCommonRuleSet: 18,000 (25.7%)\n  BotControl:                  12,000 (17.1%)\n  SQLiRuleSet:                  5,000 (7.1%)\n  IPReputationList:             4,000 (5.7%)\n  RateLimitLogin:               2,000 (2.9%)\n  GeoRestriction:               1,000 (1.4%)\n\nTOP BLOCKED IPs:\n  185.x.x.x:     8,400 requests (rate limited)\n  45.x.x.x:      5,200 requests (bot detected)\n  198.x.x.x:     3,100 requests (SQLi attempts)\n\nATTACK TYPES BLOCKED:\n  Credential stuffing (login endpoint):  2,000\n  SQL injection attempts:                5,000\n  Cross-site scripting:                  3,200\n  Known bad bot traffic:                12,000\n  Rate limit violations:               28,000\n\nWAF RULE HEALTH:\n  Rules in Block mode:    8 \u002F 10\n  Rules in Count mode:    2 \u002F 10 (under evaluation)\n  False positive rate:    \u003C 0.1%\n```\n","# Securing API Gateway with AWS WAF\n\n## When to Use\n\n- When deploying API Gateway endpoints that require protection against common web attacks\n- When implementing rate limiting and throttling to prevent API abuse and DDoS attacks\n- When building bot detection and mitigation for API endpoints exposed to the internet\n- When compliance requires WAF protection for all public-facing API endpoints\n- When customizing access controls based on IP reputation, geolocation, or request patterns\n\n**Do not use** for network-level DDoS protection (use AWS Shield), for application logic vulnerabilities (use SAST\u002FDAST tools), or for internal API security between microservices (use service mesh authentication and authorization).\n\n## Prerequisites\n\n- AWS API Gateway (REST or HTTP API) deployed with public endpoints\n- IAM permissions for `wafv2:*` and `apigateway:*` operations\n- CloudWatch and S3 or Kinesis Firehose configured for WAF logging\n- Understanding of the API's expected traffic patterns for rate limiting configuration\n- IP reputation lists or threat intelligence feeds for custom IP blocking\n\n## Workflow\n\n### Step 1: Create a WAF Web ACL with Managed Rule Groups\n\nCreate a Web ACL with AWS Managed Rules for baseline protection against OWASP Top 10 attacks.\n\n```bash\n# Create a WAF Web ACL with managed rule groups\naws wafv2 create-web-acl \\\n  --name api-gateway-waf \\\n  --scope REGIONAL \\\n  --default-action '{\"Allow\":{}}' \\\n  --visibility-config '{\n    \"SampledRequestsEnabled\": true,\n    \"CloudWatchMetricsEnabled\": true,\n    \"MetricName\": \"api-gateway-waf\"\n  }' \\\n  --rules '[\n    {\n      \"Name\": \"AWSManagedRulesCommonRuleSet\",\n      \"Priority\": 1,\n      \"Statement\": {\n        \"ManagedRuleGroupStatement\": {\n          \"VendorName\": \"AWS\",\n          \"Name\": \"AWSManagedRulesCommonRuleSet\"\n        }\n      },\n      \"OverrideAction\": {\"None\": {}},\n      \"VisibilityConfig\": {\n        \"SampledRequestsEnabled\": true,\n        \"CloudWatchMetricsEnabled\": true,\n        \"MetricName\": \"CommonRuleSet\"\n      }\n    },\n    {\n      \"Name\": \"AWSManagedRulesKnownBadInputsRuleSet\",\n      \"Priority\": 2,\n      \"Statement\": {\n        \"ManagedRuleGroupStatement\": {\n          \"VendorName\": \"AWS\",\n          \"Name\": \"AWSManagedRulesKnownBadInputsRuleSet\"\n        }\n      },\n      \"OverrideAction\": {\"None\": {}},\n      \"VisibilityConfig\": {\n        \"SampledRequestsEnabled\": true,\n        \"CloudWatchMetricsEnabled\": true,\n        \"MetricName\": \"KnownBadInputs\"\n      }\n    },\n    {\n      \"Name\": \"AWSManagedRulesSQLiRuleSet\",\n      \"Priority\": 3,\n      \"Statement\": {\n        \"ManagedRuleGroupStatement\": {\n          \"VendorName\": \"AWS\",\n          \"Name\": \"AWSManagedRulesSQLiRuleSet\"\n        }\n      },\n      \"OverrideAction\": {\"None\": {}},\n      \"VisibilityConfig\": {\n        \"SampledRequestsEnabled\": true,\n        \"CloudWatchMetricsEnabled\": true,\n        \"MetricName\": \"SQLiRuleSet\"\n      }\n    },\n    {\n      \"Name\": \"AWSManagedRulesAmazonIpReputationList\",\n      \"Priority\": 4,\n      \"Statement\": {\n        \"ManagedRuleGroupStatement\": {\n          \"VendorName\": \"AWS\",\n          \"Name\": \"AWSManagedRulesAmazonIpReputationList\"\n        }\n      },\n      \"OverrideAction\": {\"None\": {}},\n      \"VisibilityConfig\": {\n        \"SampledRequestsEnabled\": true,\n        \"CloudWatchMetricsEnabled\": true,\n        \"MetricName\": \"IPReputationList\"\n      }\n    }\n  ]'\n```\n\n### Step 2: Add Rate Limiting Rules\n\nConfigure rate-based rules to throttle excessive API requests per IP address.\n\n```bash\n# Get the Web ACL ARN and lock token\nWEB_ACL_ARN=$(aws wafv2 list-web-acls --scope REGIONAL \\\n  --query \"WebACLs[?Name=='api-gateway-waf'].ARN\" --output text)\n\n# Update Web ACL to add rate limiting rule\naws wafv2 update-web-acl \\\n  --name api-gateway-waf \\\n  --scope REGIONAL \\\n  --id $(aws wafv2 list-web-acls --scope REGIONAL --query \"WebACLs[?Name=='api-gateway-waf'].Id\" --output text) \\\n  --lock-token $(aws wafv2 get-web-acl --name api-gateway-waf --scope REGIONAL --id WEB_ACL_ID --query 'LockToken' --output text) \\\n  --default-action '{\"Allow\":{}}' \\\n  --visibility-config '{\n    \"SampledRequestsEnabled\": true,\n    \"CloudWatchMetricsEnabled\": true,\n    \"MetricName\": \"api-gateway-waf\"\n  }' \\\n  --rules '[\n    {\n      \"Name\": \"RateLimitPerIP\",\n      \"Priority\": 0,\n      \"Statement\": {\n        \"RateBasedStatement\": {\n          \"Limit\": 2000,\n          \"AggregateKeyType\": \"IP\"\n        }\n      },\n      \"Action\": {\"Block\": {}},\n      \"VisibilityConfig\": {\n        \"SampledRequestsEnabled\": true,\n        \"CloudWatchMetricsEnabled\": true,\n        \"MetricName\": \"RateLimitPerIP\"\n      }\n    },\n    {\n      \"Name\": \"RateLimitLoginEndpoint\",\n      \"Priority\": 5,\n      \"Statement\": {\n        \"RateBasedStatement\": {\n          \"Limit\": 100,\n          \"AggregateKeyType\": \"IP\",\n          \"ScopeDownStatement\": {\n            \"ByteMatchStatement\": {\n              \"FieldToMatch\": {\"UriPath\": {}},\n              \"PositionalConstraint\": \"STARTS_WITH\",\n              \"SearchString\": \"\u002Fapi\u002Fauth\u002Flogin\",\n              \"TextTransformations\": [{\"Priority\": 0, \"Type\": \"LOWERCASE\"}]\n            }\n          }\n        }\n      },\n      \"Action\": {\"Block\": {}},\n      \"VisibilityConfig\": {\n        \"SampledRequestsEnabled\": true,\n        \"CloudWatchMetricsEnabled\": true,\n        \"MetricName\": \"RateLimitLogin\"\n      }\n    }\n  ]'\n```\n\n### Step 3: Implement Bot Control\n\nAdd AWS WAF Bot Control to detect and manage automated traffic.\n\n```bash\n# Add Bot Control managed rule group\n# (Add to the rules array when updating the Web ACL)\n{\n  \"Name\": \"AWSManagedRulesBotControlRuleSet\",\n  \"Priority\": 6,\n  \"Statement\": {\n    \"ManagedRuleGroupStatement\": {\n      \"VendorName\": \"AWS\",\n      \"Name\": \"AWSManagedRulesBotControlRuleSet\",\n      \"ManagedRuleGroupConfigs\": [{\n        \"AWSManagedRulesBotControlRuleSet\": {\n          \"InspectionLevel\": \"COMMON\"\n        }\n      }],\n      \"ExcludedRules\": [\n        {\"Name\": \"CategoryHttpLibrary\"},\n        {\"Name\": \"SignalNonBrowserUserAgent\"}\n      ]\n    }\n  },\n  \"OverrideAction\": {\"None\": {}},\n  \"VisibilityConfig\": {\n    \"SampledRequestsEnabled\": true,\n    \"CloudWatchMetricsEnabled\": true,\n    \"MetricName\": \"BotControl\"\n  }\n}\n```\n\n### Step 4: Create Custom Rules for API-Specific Protection\n\nBuild custom WAF rules for API-specific security requirements.\n\n```bash\n# Block requests without required API key header\n{\n  \"Name\": \"RequireAPIKey\",\n  \"Priority\": 7,\n  \"Statement\": {\n    \"NotStatement\": {\n      \"Statement\": {\n        \"ByteMatchStatement\": {\n          \"FieldToMatch\": {\n            \"SingleHeader\": {\"Name\": \"x-api-key\"}\n          },\n          \"PositionalConstraint\": \"EXACTLY\",\n          \"SearchString\": \"\",\n          \"TextTransformations\": [{\"Priority\": 0, \"Type\": \"NONE\"}]\n        }\n      }\n    }\n  },\n  \"Action\": {\"Block\": {\"CustomResponse\": {\"ResponseCode\": 403}}},\n  \"VisibilityConfig\": {\n    \"SampledRequestsEnabled\": true,\n    \"CloudWatchMetricsEnabled\": true,\n    \"MetricName\": \"RequireAPIKey\"\n  }\n}\n\n# Geo-restrict to allowed countries\n{\n  \"Name\": \"GeoRestriction\",\n  \"Priority\": 8,\n  \"Statement\": {\n    \"NotStatement\": {\n      \"Statement\": {\n        \"GeoMatchStatement\": {\n          \"CountryCodes\": [\"US\", \"CA\", \"GB\", \"DE\", \"FR\", \"AU\"]\n        }\n      }\n    }\n  },\n  \"Action\": {\"Block\": {}},\n  \"VisibilityConfig\": {\n    \"SampledRequestsEnabled\": true,\n    \"CloudWatchMetricsEnabled\": true,\n    \"MetricName\": \"GeoRestriction\"\n  }\n}\n\n# Block oversized request bodies (prevent payload attacks)\n{\n  \"Name\": \"MaxBodySize\",\n  \"Priority\": 9,\n  \"Statement\": {\n    \"SizeConstraintStatement\": {\n      \"FieldToMatch\": {\"Body\": {\"OversizeHandling\": \"MATCH\"}},\n      \"ComparisonOperator\": \"GT\",\n      \"Size\": 10240,\n      \"TextTransformations\": [{\"Priority\": 0, \"Type\": \"NONE\"}]\n    }\n  },\n  \"Action\": {\"Block\": {}},\n  \"VisibilityConfig\": {\n    \"SampledRequestsEnabled\": true,\n    \"CloudWatchMetricsEnabled\": true,\n    \"MetricName\": \"MaxBodySize\"\n  }\n}\n```\n\n### Step 5: Associate WAF with API Gateway and Enable Logging\n\nAttach the Web ACL to the API Gateway stage and configure comprehensive logging.\n\n```bash\n# Associate Web ACL with API Gateway\naws wafv2 associate-web-acl \\\n  --web-acl-arn $WEB_ACL_ARN \\\n  --resource-arn arn:aws:apigateway:us-east-1::\u002Frestapis\u002FAPI_ID\u002Fstages\u002Fprod\n\n# Enable WAF logging to S3 via Kinesis Firehose\naws wafv2 put-logging-configuration \\\n  --logging-configuration '{\n    \"ResourceArn\": \"'$WEB_ACL_ARN'\",\n    \"LogDestinationConfigs\": [\n      \"arn:aws:firehose:us-east-1:ACCOUNT:deliverystream\u002Faws-waf-logs-api-gateway\"\n    ],\n    \"RedactedFields\": [\n      {\"SingleHeader\": {\"Name\": \"authorization\"}},\n      {\"SingleHeader\": {\"Name\": \"cookie\"}}\n    ]\n  }'\n\n# Verify association\naws wafv2 get-web-acl-for-resource \\\n  --resource-arn arn:aws:apigateway:us-east-1::\u002Frestapis\u002FAPI_ID\u002Fstages\u002Fprod\n```\n\n### Step 6: Monitor WAF Metrics and Tune Rules\n\nMonitor WAF effectiveness and tune rules to reduce false positives.\n\n```bash\n# Get WAF metrics from CloudWatch\naws cloudwatch get-metric-statistics \\\n  --namespace AWS\u002FWAFV2 \\\n  --metric-name BlockedRequests \\\n  --dimensions Name=WebACL,Value=api-gateway-waf Name=Rule,Value=ALL \\\n  --start-time 2026-02-22T00:00:00Z \\\n  --end-time 2026-02-23T00:00:00Z \\\n  --period 3600 \\\n  --statistics Sum\n\n# Get sampled requests for a specific rule\naws wafv2 get-sampled-requests \\\n  --web-acl-arn $WEB_ACL_ARN \\\n  --rule-metric-name RateLimitPerIP \\\n  --scope REGIONAL \\\n  --time-window '{\"StartTime\":\"2026-02-22T00:00:00Z\",\"EndTime\":\"2026-02-23T00:00:00Z\"}' \\\n  --max-items 50\n\n# Check rate-limited IPs\naws wafv2 get-rate-based-statement-managed-keys \\\n  --web-acl-name api-gateway-waf \\\n  --scope REGIONAL \\\n  --web-acl-id WEB_ACL_ID \\\n  --rule-name RateLimitPerIP\n\n# Create CloudWatch alarm for high block rate\naws cloudwatch put-metric-alarm \\\n  --alarm-name waf-high-block-rate \\\n  --namespace AWS\u002FWAFV2 \\\n  --metric-name BlockedRequests \\\n  --dimensions Name=WebACL,Value=api-gateway-waf Name=Rule,Value=ALL \\\n  --statistic Sum --period 300 --threshold 1000 \\\n  --comparison-operator GreaterThanThreshold \\\n  --evaluation-periods 2 \\\n  --alarm-actions arn:aws:sns:us-east-1:ACCOUNT:security-alerts\n```\n\n## Key Concepts\n\n| Term | Definition |\n|------|------------|\n| Web ACL | AWS WAF access control list that defines the collection of rules and their actions (allow, block, count) applied to associated resources |\n| Managed Rule Group | Pre-configured set of WAF rules maintained by AWS or third-party vendors for common attack patterns like OWASP Top 10 |\n| Rate-Based Rule | WAF rule that tracks request rates per IP address and blocks traffic exceeding a defined threshold within a 5-minute window |\n| Bot Control | AWS WAF managed rule group that identifies and manages automated traffic including scrapers, crawlers, and attack bots |\n| IP Reputation List | AWS-maintained list of IP addresses associated with malicious activity including botnets, scanners, and known attackers |\n| Custom Response | WAF capability to return specific HTTP status codes and custom response bodies when blocking requests |\n\n## Tools & Systems\n\n- **AWS WAF**: Web application firewall service for protecting API Gateway, ALB, CloudFront, and AppSync endpoints\n- **AWS Managed Rules**: Pre-built rule groups for common attack patterns maintained by AWS security team\n- **AWS Firewall Manager**: Central management of WAF policies across multiple accounts in AWS Organizations\n- **Kinesis Firehose**: Streaming delivery service for WAF logs to S3, Elasticsearch, or third-party analytics\n- **CloudWatch**: Monitoring service for WAF metrics including allowed, blocked, and counted requests\n\n## Common Scenarios\n\n### Scenario: Protecting a Public API from Credential Stuffing and Bot Attacks\n\n**Context**: A public REST API experiences thousands of authentication attempts per hour from automated bots attempting credential stuffing against the `\u002Fapi\u002Fauth\u002Flogin` endpoint.\n\n**Approach**:\n1. Create a Web ACL with AWS Managed Rules Common Rule Set for baseline protection\n2. Add a rate-based rule limiting the login endpoint to 100 requests per IP per 5 minutes\n3. Enable Bot Control managed rules to detect and block automated traffic\n4. Add IP Reputation List to block known malicious IPs proactively\n5. Create a custom rule blocking requests without proper User-Agent headers\n6. Enable WAF logging and create CloudWatch alarms for high block rates\n7. Review sampled blocked requests weekly to tune rules and reduce false positives\n\n**Pitfalls**: Rate limiting by IP can block legitimate users behind shared NAT gateways or corporate proxies. Consider using API key or authenticated session-based rate limiting for more granular control. Bot Control rules in COMMON inspection level may block legitimate API clients; start in Count mode and review before switching to Block.\n\n## Output Format\n\n```\nAWS WAF API Gateway Security Report\n======================================\nWeb ACL: api-gateway-waf\nAssociated Resource: API Gateway - production-api (prod stage)\nReport Period: 2026-02-16 to 2026-02-23\n\nTRAFFIC SUMMARY:\n  Total requests:              2,450,000\n  Allowed requests:            2,380,000 (97.1%)\n  Blocked requests:               70,000 (2.9%)\n\nBLOCKS BY RULE:\n  RateLimitPerIP:              28,000 (40%)\n  AWSManagedRulesCommonRuleSet: 18,000 (25.7%)\n  BotControl:                  12,000 (17.1%)\n  SQLiRuleSet:                  5,000 (7.1%)\n  IPReputationList:             4,000 (5.7%)\n  RateLimitLogin:               2,000 (2.9%)\n  GeoRestriction:               1,000 (1.4%)\n\nTOP BLOCKED IPs:\n  185.x.x.x:     8,400 requests (rate limited)\n  45.x.x.x:      5,200 requests (bot detected)\n  198.x.x.x:     3,100 requests (SQLi attempts)\n\nATTACK TYPES BLOCKED:\n  Credential stuffing (login endpoint):  2,000\n  SQL injection attempts:                5,000\n  Cross-site scripting:                  3,200\n  Known bad bot traffic:                12,000\n  Rate limit violations:               28,000\n\nWAF RULE HEALTH:\n  Rules in Block mode:    8 \u002F 10\n  Rules in Count mode:    2 \u002F 10 (under evaluation)\n  False positive rate:    \u003C 0.1%\n```\n",{"name":5,"tags":25,"author":33,"domain":34,"license":15,"version":35,"nist_csf":36,"subdomain":26,"description":41,"mitre_attack":42},[26,27,28,29,30,31,32],"cloud-security","aws","waf","api-gateway","rate-limiting","bot-protection","owasp","mahipal","cybersecurity","1.0",[37,38,39,40],"PR.IR-01","ID.AM-08","GV.SC-06","DE.CM-01","Secures AWS API Gateway endpoints with AWS WAF by configuring managed rule groups for OWASP Top 10 protection, custom rate-limiting rules, bot control, IP reputation filtering, and WAF metric monitoring. Use when deploying API Gateway endpoints that need protection against common web attacks, or when implementing rate limiting and throttling to prevent API abuse and DDoS.\n",[43,44,45,46,47],"T1078.004","T1530","T1537","T1580","T0816","main","7540bbccf0c1ded6156a467b02c95b61ad62413f",".agents\u002Fskills\u002Fsecuring-api-gateway-with-aws-waf","https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu","https:\u002F\u002Fgithub.com\u002FNeelakshSaxena","Currently exploring the intersection of tech","2026-09-11 03:02:31",{"source":8,"skillName":5,"commands":56,"prompt":66,"zipAvailable":67},[57,60,63],{"tool":58,"command":59},"npx","npx skills add NeelakshSaxena\u002FVayu --skill securing-api-gateway-with-aws-waf",{"tool":61,"command":62},"bunx","bunx skills add NeelakshSaxena\u002FVayu --skill securing-api-gateway-with-aws-waf",{"tool":64,"command":65},"pnpm","pnpm dlx skills add NeelakshSaxena\u002FVayu --skill securing-api-gateway-with-aws-waf","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fsecuring-api-gateway-with-aws-waf\u002FSKILL.md",true,[69,73,79],{"path":70,"resourceType":70,"resourceTypeDesc":71,"sizeBytes":72,"sourceHtmlUrl":16},"LICENSE","许可证",11255,{"path":74,"resourceType":75,"resourceTypeDesc":76,"sizeBytes":77,"sourceHtmlUrl":78},"references\u002Fapi-reference.md","REFERENCE","参考文档",2315,"https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fsecuring-api-gateway-with-aws-waf\u002Freferences\u002Fapi-reference.md",{"path":80,"resourceType":81,"resourceTypeDesc":82,"sizeBytes":83,"sourceHtmlUrl":84},"scripts\u002Fagent.py","SCRIPT","脚本",7214,"https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fsecuring-api-gateway-with-aws-waf\u002Fscripts\u002Fagent.py",[86,93,100,107,114,121],{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":20},"01M7ACCCVNCFKMA9X6D15X6G98","runpodctl","Runpod CLI for managing GPU\u002FCPU workloads from the terminal — pods, serverless endpoints, templates, network volumes, Hub deploys, models, SSH, and file transfer (send\u002Freceive). Use for terminal\u002FCI\u002Fscripting, Hub browse\u002Fdeploy, SSH setup, `doctor`, or when the Runpod MCP tools are not connected. For structured tool calls in an MCP-enabled session, prefer runpod-mcp.","https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Frunpodctl\u002FSKILL.md",[],[],{"skillNo":94,"name":95,"nameZh":6,"description":96,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":97,"categories":98,"keywords":99,"publishedAt":20},"01M7ACC63SRHEA5KMCHSMZK2TC","runpod","Start here for any Runpod task — running GPU\u002FCPU pods, deploying serverless endpoints, templates, network volumes, building images, or understanding how Runpod works. Routes to the right skill (runpod-mcp, runpodctl, flash, companion-clis, runpod-usage, runpod-templates, runpod-migrate) and indexes two dozen live-verified end-to-end examples (golden paths) — use it when the lane is unclear, and for any multi-step or provisioning task even when it is not.","https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Frunpod\u002FSKILL.md",[],[],{"skillNo":101,"name":102,"nameZh":6,"description":103,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":104,"categories":105,"keywords":106,"publishedAt":20},"01M7ACC0Q1C89N9BZBV91CTQTF","runpod-usage","How Runpod works and how to work it — pods vs serverless, GPU\u002FVRAM selection, storage, building a container, networking, plus the agentic pod development loop (provision → ssh-exec → set up → poll readiness) and on-pod install hygiene (uv\u002Fapt). Use to answer \"how does X work\", \"which GPU\", \"how do I build a container\", or \"how do I stand up a workload on a pod\". Guidance, not a tool — execute with runpodctl, runpod-mcp, or flash.","https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Frunpod-usage\u002FSKILL.md",[],[],{"skillNo":108,"name":109,"nameZh":6,"description":110,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":111,"categories":112,"keywords":113,"publishedAt":20},"01M7ACBRPE345GF5GM5B8P8RRC","runpod-templates","Runpod's official prebuilt pod templates (ComfyUI, PyTorch, and others): what each image ships, which ports and paths it uses, how to pick one, how to pin a version, and what is missing on first boot. Use when a task says \"run \u003CX> on a pod\" and an official template already covers it, instead of building an image — and when a user needs help with or wants to fix something about a Runpod template they are already running (won't boot, can't reach the UI, missing models, wrong CUDA line, broken ComfyUI workflow metadata on imported workflows): start here and route onward. Deploy with runpodctl or runpod-mcp; end-to-end walkthroughs live in the runpod router's golden paths.","https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Frunpod-templates\u002FSKILL.md",[],[],{"skillNo":115,"name":116,"nameZh":6,"description":117,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":118,"categories":119,"keywords":120,"publishedAt":20},"01M7ACBJATHKVX1TWES2F44GY8","runpod-migrate","Migrate a codebase from the Runpod GraphQL API or REST v1 to REST v2 — inventory which parts use which API version, rewrite the call sites, flag breaking changes, and verify. Use when someone asks to move to v2, asks what v2 would change, or asks which Runpod API their code is on. For managing infrastructure rather than migrating code, use runpod-mcp or runpodctl.","https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Frunpod-migrate\u002FSKILL.md",[],[],{"skillNo":122,"name":123,"nameZh":6,"description":124,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":125,"categories":126,"keywords":127,"publishedAt":20},"01M7ACBC7GHVH6T9YEAPCG2AP8","runpod-mcp","Manage Runpod infrastructure — pods, serverless endpoints, jobs, templates, network volumes, container-registry auth, GPU\u002FCPU catalog, and billing — via the Runpod MCP server's structured tool calls. Use when the Runpod MCP tools (create-pod, list-endpoints, …) are connected in this session, or to connect them (hosted OAuth or local npx). Prefer this over runpodctl for plain infra CRUD when MCP is available; use runpodctl for the terminal, file transfer, or SSH setup.","https:\u002F\u002Fgithub.com\u002FNeelakshSaxena\u002FVayu\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Frunpod-mcp\u002FSKILL.md",[],[]]