
An AWS CloudFormation template used to provision and manage AWS WAFv2 resources, including a Web ACL, managed rule groups, a custom regex pattern set, and an IP set.
An AWS CloudFormation template used to provision and manage AWS WAFv2 resources, including a Web ACL, managed rule groups, a custom regex pattern set, and an IP set.

The template provisions:
AWS::WAFv2::WebACL.AWSManagedRulesCommonRuleSetAWSManagedRulesKnownBadInputsRuleSetAWSManagedRulesAmazonIpReputationListAWSManagedRulesAnonymousIpListAWSManagedRulesSQLiRuleSetCustomRuleEncodeHTML) that can be enabled to block encoded/suspicious query string input.CustomRuleRejectIP) that can be enabled to block selected source IPs.CloudWatchLogGroup) to store the WebACL logs.The stack exports the Web ACL ARN as ${StackName}-aclarn.
The template accepts the following parameters:
Name
Scope
CLOUDFRONT or REGIONAL.RegularExpressionsList
^(.*<.*)+$,^(.*>.*)+$,^(.*".*)+$,^(.*'.*)+$).MyIPSetDenylist
203.0.113.10/32,198.51.100.0/24).For
Scope=CLOUDFRONT, run deployments inus-east-1.
Use CloudFormation deploy to create or update the stack.
Login to your AWS account and clink the quick link to deploy in CloudFormation (recommended), or
Download the template and deploy manually in the CloudFormation console, especially if you'd like to customize it.
aws cloudformation deploy \
--template-file waf.yaml \
--stack-name waf-standard-regional \
--capabilities CAPABILITY_NAMED_IAM \
--parameter-overrides \
Name=StandardACL \
Scope=REGIONAL \
RegularExpressionsList="^(.*<.*)+$,^(.*>.*)+$,^(.*\".*)+$,^(.*'.*)+$" \
MyIPSetDenylist="203.0.113.10/32,198.51.100.0/24"
aws cloudformation deploy \
--region us-east-1 \
--template-file waf.yaml \
--stack-name waf-standard-cloudfront \
--capabilities CAPABILITY_NAMED_IAM \
--parameter-overrides \
Name=StandardACL \
Scope=CLOUDFRONT \
RegularExpressionsList="^(.*<.*)+$,^(.*>.*)+$,^(.*\".*)+$,^(.*'.*)+$" \
MyIPSetDenylist="203.0.113.10/32,198.51.100.0/24"
After deployment, associate the Web ACL ARN output with your resource:
Scope=CLOUDFRONT).Scope=REGIONAL).You can retrieve stack outputs with:
aws cloudformation describe-stacks \
--stack-name waf-standard-regional \
--query 'Stacks[0].Outputs'
If valid traffic is blocked by AWS Managed Rules, use one or more of the following approaches:
These can be done manually, or using the helper script.