Subchapter 96.4
references/creating-a-web-acl-and-associating-it-with-a-resource.mdMarkdown9 KBView on GitHub
Domain expertise for putting AWS WAF in front of an application: creating a web access control list
(web ACL) and associating it with the resource it protects. Covers the immutable scope choice
(CLOUDFRONT in versus in the resource’s Region), the fact that a web ACL
filters nothing until it is associated, the one-web-ACL-per-resource and CloudFront-only
constraints, and starting rules in Count mode.
us-east-1REGIONALDoes not cover the rules that go inside the web ACL (managed rules, rate-based, match, bot, fraud); those are separate references. CloudFront distribution and Application Load Balancer configuration are their own skills.
Execute commands using the AWS MCP server when connected (sandboxed execution, audit logging, observability). Fall back to the AWS CLI otherwise.
To create a web ACL and associate it end to end, follow the procedure exactly. See the Procedure section below.
The procedure covers:
| Resource | Scope | Region |
|---|---|---|
| CloudFront distribution | CLOUDFRONT | us-east-1 (required) |
| Application Load Balancer, API Gateway REST API, AppSync GraphQL API, Cognito user pool, App Runner, Verified Access, Amplify | REGIONAL | the resource’s own Region |
Constraints:
CLOUDFRONT web ACL in us-east-1 regardless of where the distribution servesREGIONAL web ACL in the same Region as the resource it protectsThe credentials that run these commands should carry only the WAF actions the task needs, not broad access.
Constraints:
wafv2: actions these procedures use — for the entry-point
workflow that is wafv2:CreateWebACL, wafv2:GetWebACL, wafv2:UpdateWebACL, and
wafv2:AssociateWebACL — rather than wafv2:* or the AWSWAFFullAccess managed policywafv2:PutLoggingConfiguration for logging, wafv2:CreateIPSet/wafv2:UpdateIPSet for IP sets),
granting only what each task requiresaws sts assume-role) rather than long-lived IAM user access keys when running these commandsA web ACL inspects no traffic until it is associated with a resource. Customers finish the web ACL and assume traffic is filtered.
Constraints:
Each resource can have only one web ACL, and a web ACL associated with a CloudFront distribution cannot be associated with any other resource type. Customers design around a shared web ACL that cannot exist.
Constraints:
Enabling rules straight to Block can take down legitimate traffic. The recommended path for a first web ACL is Count, then Block after review.
Constraints:
The web ACL was created in the wrong scope or Region. Recreate it as CLOUDFRONT scope in
us-east-1 (Decision: scope).
The web ACL is not associated with the resource. Associate it (A web ACL filters nothing until associated).
CloudFront web ACLs are exclusive and each resource takes one web ACL. Create separate web ACLs (One web ACL per resource, CloudFront is exclusive).
This procedure creates a web ACL in the correct scope, associates it with the resource, and surfaces the console link to verify.
CLOUDFRONT or REGIONAL, derived from the resource type.Allow or Block when no rule matches. Set this deliberately to
match the intended posture; an Allow default passes any traffic not matched by a rule through
unfiltered, so prefer Block as the secure default and use Allow only when explicit blocking
rules carry the enforcement.Constraints for parameter acquisition:
Constraints:
aws sts get-caller-identityConstraints:
You MUST create the web ACL in the correct scope and Region:
aws wafv2 create-web-acl --name {web_acl_name} --scope {scope} \
--default-action {default_action}={} \
--visibility-config SampledRequestsEnabled=true,CloudWatchMetricsEnabled=true,MetricName={web_acl_name} \
--region {region}You MUST capture the web ACL ARN and id from the response
Constraints:
You MUST associate the web ACL with the resource ARN:
aws wafv2 associate-web-acl --web-acl-arn {web_acl_arn} --resource-arn {resource_arn} --region {region}You MUST NOT consider the setup complete until the association succeeds
Constraints:
You MUST confirm the association and present the AWS WAF console link, telling the customer to open it and confirm the web ACL and its associated resource:
https://us-east-1.console.aws.amazon.com/wafv2/homev2/web-acls?region={region}{
"web_acl_name": "example-frontend-webacl",
"resource_arn": "arn:aws:cloudfront::111122223333:distribution/EDFDVBD6EXAMPLE",
"scope": "CLOUDFRONT",
"default_action": "Block"
}(Block is the secure default — unmatched requests are denied, and Allow rules admit the
traffic you intend. Use "default_action": "Allow" only when the customer explicitly wants an
allow-by-default web ACL whose rules do the blocking.)
Created CLOUDFRONT web ACL example-frontend-webacl in us-east-1 with default action Block.
Associated it with distribution EDFDVBD6EXAMPLE.
Open the AWS WAF console and confirm the web ACL and its associated resource:
https://us-east-1.console.aws.amazon.com/wafv2/homev2/web-acls?region=us-east-1The web ACL is in the wrong scope or Region. Recreate as CLOUDFRONT in us-east-1 (Step 2).
The web ACL is not associated. Associate it (Step 3).
This procedure modifies a security control, so misconfiguration directly weakens the application’s defenses.
wafv2: actions a task needs (for example wafv2:GetWebACL and wafv2:UpdateWebACL) rather than wafv2:* or the AWSWAFFullAccess managed policy.aws sts assume-role) rather than long-lived IAM user access keys when running these WAF CLI commands.wafv2 management events and set CloudWatch alarms on critical web ACL configuration changes (such as DeleteWebACL and UpdateWebACL rule removals) and on the web ACL’s BlockedRequests and CountedRequests metrics, so rule changes and sudden spikes in blocked or counted traffic are detected.