The Complete Production SOP: How to Deploy and Run AWS WAF Managed Rule Groups & Web ACL Rules in Autonomous AI Agents
Step-by-step SOP to install and run AWS WAF Managed Rule Groups in Codex, Claude Code, & Cursor. Includes verified prompts, terraform, and troubleshooting.
Technical Overview & Architectural Context
When autonomous coding agents generate AWS WAF configurations (via Terraform, CloudFormation, or AWS CDK), they routinely commit catastrophic architectural mistakes. Common failure modes include configuring AWS WAF Managed Rules directly to 'Block' mode without an evaluation period, omitting the mandatory 'none: {}' or 'count: {}' override blocks inside WAFv2 statements, confusing Regional (ALB) and CLOUDFRONT scopes, and failing to define sampled request metrics. These mistakes lead to accidental enterprise outages, dropped legitimate traffic, and broken deployment pipelines. Without strict procedural boundaries, agents also struggle to correctly sequence rate-based statement aggregations and IP set exclusions. The 'aws-waf-managed-rule-groups' skill bridges this gap by enforcing deterministic Infrastructure-as-Code (IaC) guardrails. It mandates staging rules in 'Count' mode, establishes explicit capacity unit (WCU) calculations, forces CloudWatch metric subscriptions, and validates Web ACL association schemas before changes touch deployment pipelines.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Mount the skill manifest into your agent runtime workspace or global skills directory.
Agent runtimes such as Claude Code, Codex Desktop, Windsurf, and Cursor discover contextual skills via local manifest directories (.agents/skills/ or .claude/skills/). Injecting SKILL.md registers the frontmatter triggers and sets sandboxed file system boundaries so the agent knows precisely when and how to synthesize AWS WAF rules.
mkdir -p .agents/skills/aws-waf-managed-rule-groups && cat << 'EOF' > .agents/skills/aws-waf-managed-rule-groups/SKILL.md
---
name: "aws-waf-managed-rule-groups"
description: "Deploy AWS WAF to protect CloudFront distributions and Application Load Balancers."
metadata:
author: "AWS"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "configure aws waf web acl"
- "enable aws managed rule sets"
- "create rate-based rule aws waf"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---
# AWS WAF Managed Rule Groups & Web ACL Rules
Configures AWS WAF v2 Web ACLs: AWSManagedRulesCommonRuleSet, AWSManagedRulesSQLiRuleSet, rate-based rules, IP sets, custom response headers, and CloudWatch alarm metrics.
## When to Invoke
Invoke this skill whenever you need to:
- configure aws waf web acl
- enable aws managed rule sets
- create rate-based rule aws waf
## Execution SOP & Rules
1. Associate Web ACLs with CloudFront distributions or Application Load Balancers.
2. Enable core managed rule groups: CommonRuleSet, SQLiRuleSet, and LinuxRuleSet.
3. Set rule actions to Count mode initially to evaluate impact before switching to Block.
4. Enable CloudWatch metrics on Web ACL rules to trigger automated SNS alert notifications.
## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
EOF---
name: "aws-waf-managed-rule-groups"
description: "Deploy AWS WAF to protect CloudFront distributions and Application Load Balancers."
metadata:
author: "AWS"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "configure aws waf web acl"
- "enable aws managed rule sets"
- "create rate-based rule aws waf"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---Keep the SKILL.md focused on operational SOPs and validation steps rather than full raw code templates to conserve context tokens across multi-turn agent chats.
Ensure permissions.shell_exec remains set to false unless you deliberately require the agent to execute terraform apply or aws wafv2 directly on live infrastructure.
Environment Secrets & Dependency Validation
Configure target deployment variables without exposing AWS credentials to the agent conversation context.
When invoking an agent to build IaC for AWS WAF, credential leaks must be prevented. Configure workspace variables using environment files that are ignored by Git. Instruct the agent to reference environment provider blocks or IAM role assumptions rather than hardcoded keys.
echo 'AWS_REGION=us-east-1' >> .env.local && echo '.env.local' >> .gitignoreAlways remind the agent in the prompt to use AWS STS AssumeRole blocks or standard credential chains in synthesized Terraform/CDK blocks.
CloudFront WAF Web ACLs MUST always be deployed to us-east-1 regardless of your primary application region, whereas ALB Web ACLs must match the load balancer's AWS region.
Intent Matching & Trigger Invocation
Activate the skill using frontmatter triggers to generate a complete WAFv2 Web ACL configuration.
Provide a prompt that contains one or more exact trigger phrases (such as 'configure aws waf web acl' or 'enable aws managed rule sets'). The agent runtime will parse SKILL.md and strictly follow the procedural SOP, defaulting new managed rules to 'count' mode and creating CloudWatch metrics.
resource "aws_wafv2_web_acl" "main" {
name = "production-web-acl"
description = "Managed rule groups with rate limiting in count/evaluation mode"
scope = "REGIONAL"
default_action {
allow {}
}
rule {
name = "AWS-AWSManagedRulesCommonRuleSet"
priority = 1
override_action {
count {}
}
statement {
managed_rule_group_statement {
name = "AWSManagedRulesCommonRuleSet"
vendor_name = "AWS"
}
}
visibility_config {
cloudwatch_metrics_enabled = true
metric_name = "ProductionWebACL-CommonRuleSet"
sampled_requests_enabled = true
}
}
rule {
name = "RateLimitRule"
priority = 2
action {
count {}
}
statement {
rate_based_statement {
limit = 2000
aggregate_key_type = "IP"
}
}
visibility_config {
cloudwatch_metrics_enabled = true
metric_name = "ProductionWebACL-RateLimit"
sampled_requests_enabled = true
}
}
visibility_config {
cloudwatch_metrics_enabled = true
metric_name = "ProductionWebACL-Total"
sampled_requests_enabled = true
}
}Use precise scope identifiers ('REGIONAL' for ALB/API Gateway, 'CLOUDFRONT' for edge distributions) in the prompt to avoid rewriting resource identifiers later.
In Terraform AWS Provider v5+, managed rule group overrides require an empty count {} or none {} block; omitting override_action causes an agent validation error.
Verification, Linting & Output Quality Gate
Run local syntax linting, WCU calculation, and formatting checks against agent output.
Validate that the agent did not exceed 1,500 AWS Web ACL capacity units (WCU) across CommonRuleSet (700 WCU), SQLiRuleSet (200 WCU), and custom rules. Execute terraform validate or tflint to catch schema mismatches before applying.
terraform fmt -check && terraform init -backend=false && terraform validateInstruct the agent to inspect git diff prior to completing execution so unexpected alterations to preexisting security groups or route tables are rejected.
Failure to initialize terraform providers prior to validation will cause the agent to falsely diagnose missing modules or provider argument failures.
Real-World Scenario: Deploying Multi-Layer AWS WAF Protection for Public Application Load Balancers
“Act as a cloud security engineer. Please configure aws waf web acl for our public Application Load Balancer in us-west-2. Enable aws managed rule sets (Common and SQLi) and create rate-based rule aws waf capping requests at 3000 per 5-minute window per IP. Start all managed rules in Count mode and wire up CloudWatch metrics.”
Runtime Troubleshooting & Failure Modes
Root Cause: The agent attempted to declare a rule.action { ... } block or omitted override_action entirely for an AWSManagedRules statement, which is invalid in the AWS WAFv2 schema.
rule {
name = "AWS-CommonRuleSet"
priority = 10
override_action {
count {}
}
statement {
managed_rule_group_statement {
name = "AWSManagedRulesCommonRuleSet"
vendor_name = "AWS"
}
}
visibility_config { ... }
}Root Cause: The Web ACL was generated with scope = 'CLOUDFRONT' (which requires us-east-1 global scope) but was associated with a Regional Application Load Balancer in another region.
Update the Web ACL definition: scope = "REGIONAL" and verify provider aws { region = "<target-alb-region>" } matches the ALB placement.Frequently Asked Questions (AWS WAF Managed Rule Groups & Web ACL Rules SOP)
Q:Can I use AWS WAF Managed Rule Groups & Web ACL Rules across Codex, Claude Code, and Cursor simultaneously?
Yes. This skill is defined according to the open SKILL.md specification. It mounts identically in Codex workspace roots, Claude Code skills paths, and Cursor/Windsurf agent instruction directories without modification.
Q:How does AWS WAF Managed Rule Groups & Web ACL Rules prevent context window overflow during long agent sessions?
Instead of stuffing hundreds of lines of example Terraform or CloudFormation manifests into system prompts, the skill defines strict operational constraints, rule ordering logic, and triggers that load on-demand when WAF intent is recognized.
Q:Does this skill require escalated root or container permissions?
No. The skill runs with a 98/100 security score: permissions are strictly constrained to workspace file reads and writes (fs_read: true, fs_write: 'workspace'), disabling arbitrary shell execution and direct outbound network calls from the agent runtime.
Ready to equip your autonomous agent with AWS WAF Managed Rule Groups & Web ACL Rules?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.