AWS::WAFv2::WebACL - Amazon CloudFormation
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

AWS::WAFv2::WebACL

Note

This is the latest version of Amazon WAF, named Amazon WAFV2, released in November, 2019. For information, including how to migrate your Amazon WAF resources from the prior release, see the Amazon WAF Developer Guide.

Use an AWS::WAFv2::WebACL to define a collection of rules to use to inspect and control web requests. Each rule has an action defined (allow, block, or count) for requests that match the statement of the rule. In the web ACL, you specify a default action to take (allow, block) for any request that doesn't match any of the rules. The rules in a web ACL can contain rule statements that you define explicitly and rule statements that reference rule groups and managed rule groups. You can associate a web ACL with one or more Amazon resources to protect. The resources can be an Amazon CloudFront distribution, an Amazon API Gateway REST API, an Application Load Balancer, an Amazon AppSync GraphQL API , an Amazon Cognito user pool, or an Amazon App Runner service.

Syntax

To declare this entity in your Amazon CloudFormation template, use the following syntax:

JSON

{ "Type" : "AWS::WAFv2::WebACL", "Properties" : { "CaptchaConfig" : CaptchaConfig, "ChallengeConfig" : ChallengeConfig, "CustomResponseBodies" : {Key: Value, ...}, "DefaultAction" : DefaultAction, "Description" : String, "Name" : String, "Rules" : [ Rule, ... ], "Scope" : String, "Tags" : [ Tag, ... ], "TokenDomains" : [ String, ... ], "VisibilityConfig" : VisibilityConfig } }

Properties

CaptchaConfig

Specifies how Amazon WAF should handle CAPTCHA evaluations for rules that don't have their own CaptchaConfig settings. If you don't specify this, Amazon WAF uses its default settings for CaptchaConfig.

Required: No

Type: CaptchaConfig

Update requires: No interruption

ChallengeConfig

Specifies how Amazon WAF should handle challenge evaluations for rules that don't have their own ChallengeConfig settings. If you don't specify this, Amazon WAF uses its default settings for ChallengeConfig.

Required: No

Type: ChallengeConfig

Update requires: No interruption

CustomResponseBodies

A map of custom response keys and content bodies. When you create a rule with a block action, you can send a custom response to the web request. You define these for the web ACL, and then use them in the rules and default actions that you define in the web ACL.

For information about customizing web requests and responses, see Customizing web requests and responses in Amazon WAF in the Amazon WAF Developer Guide.

For information about the limits on count and size for custom request and response settings, see Amazon WAF quotas in the Amazon WAF Developer Guide.

Required: No

Type: Map of CustomResponseBody

Update requires: No interruption

DefaultAction

The action to perform if none of the Rules contained in the WebACL match.

Required: Yes

Type: DefaultAction

Update requires: No interruption

Description

A description of the web ACL that helps with identification.

Required: No

Type: String

Minimum: 1

Maximum: 256

Pattern: ^[\w+=:#@/\-,\.][\w+=:#@/\-,\.\s]+[\w+=:#@/\-,\.]$

Update requires: No interruption

Name

The name of the web ACL. You cannot change the name of a web ACL after you create it.

Required: No

Type: String

Minimum: 1

Maximum: 128

Pattern: ^[\w\-]+$

Update requires: Replacement

Rules

The rule statements used to identify the web requests that you want to allow, block, or count. Each rule includes one top-level statement that Amazon WAF uses to identify matching web requests, and parameters that govern how Amazon WAF handles them.

Required: No

Type: List of Rule

Update requires: No interruption

Scope

Specifies whether this is for an Amazon CloudFront distribution or for a regional application. A regional application can be an Application Load Balancer (ALB), an Amazon API Gateway REST API, an Amazon AppSync GraphQL API, an Amazon Cognito user pool, or an Amazon App Runner service. Valid Values are CLOUDFRONT and REGIONAL.

Note

For CLOUDFRONT, you must create your WAFv2 resources in the US East (N. Virginia) Region, us-east-1.

For information about how to define the association of the web ACL with your resource, see AWS::WAFv2::WebACLAssociation.

Required: Yes

Type: String

Update requires: Replacement

Tags

Key:value pairs associated with an Amazon resource. The key:value pair can be anything you define. Typically, the tag key represents a category (such as "environment") and the tag value represents a specific value within that category (such as "test," "development," or "production"). You can add up to 50 tags to each Amazon resource.

Note

To modify tags on existing resources, use the Amazon WAF APIs or command line interface. With Amazon CloudFormation, you can only add tags to Amazon WAF resources during resource creation.

Required: No

Type: List of Tag

Update requires: No interruption

TokenDomains

Specifies the domains that Amazon WAF should accept in a web request token. This enables the use of tokens across multiple protected websites. When Amazon WAF provides a token, it uses the domain of the Amazon resource that the web ACL is protecting. If you don't specify a list of token domains, Amazon WAF accepts tokens only for the domain of the protected resource. With a token domain list, Amazon WAF accepts the resource's host domain plus all domains in the token domain list, including their prefixed subdomains.

Required: No

Type: List of String

Update requires: No interruption

VisibilityConfig

Defines and enables Amazon CloudWatch metrics and web request sample collection.

Required: Yes

Type: VisibilityConfig

Update requires: No interruption

Return values

Ref

The Ref for the resource, containing the resource name, physical ID, and scope, formatted as follows: name|id|scope.

For example: my-webacl-name|1234a1a-a1b1-12a1-abcd-a123b123456|REGIONAL.

Fn::GetAtt

The Fn::GetAttintrinsic function returns a value for a specified attribute of this type. The following are the available attributes and sample return values.

For more information about using the Fn::GetAttintrinsic function, see Fn::GetAtt.

Arn

The Amazon Resource Name (ARN) of the web ACL.

Capacity

The web ACL capacity units (WCUs) currently being used by this web ACL.

Amazon WAF uses WCUs to calculate and control the operating resources that are used to run your rules, rule groups, and web ACLs. Amazon WAF calculates capacity differently for each rule type, to reflect the relative cost of each rule. Simple rules that cost little to run use fewer WCUs than more complex rules that use more processing power. Rule group capacity is fixed at creation, which helps users plan their web ACL WCU usage when they use a rule group. The WCU limit for web ACLs is 1,500.

Id

The ID of the web ACL.

LabelNamespace

The label namespace prefix for this web ACL. All labels added by rules in this web ACL have this prefix.

The syntax for the label namespace prefix for a web ACL is the following: awswaf:<account ID>:webacl:<web ACL name>:

When a rule with a label matches a web request, Amazon WAF adds the fully qualified label to the request. A fully qualified label is made up of the label namespace from the rule group or web ACL where the rule is defined and the label from the rule, separated by a colon.

Examples

Create a web ACL with custom request and response handling

The following shows an example web ACL specification. This example includes custom request and response configurations.

YAML

ExampleWebACL: Type: 'AWS::WAFv2::WebACL' Properties: Name: ExampleWebACL1 Scope: REGIONAL Description: This is an example WebACL DefaultAction: Allow: CustomRequestHandling: InsertHeaders: - Name: AllowActionHeader1Name Value: AllowActionHeader1Value - Name: AllowActionHeader2Name Value: AllowActionHeader2Value VisibilityConfig: SampledRequestsEnabled: true CloudWatchMetricsEnabled: true MetricName: ExampleWebACLMetric CustomResponseBodies: CustomResponseBodyKey1: ContentType: TEXT_PLAIN Content: this is a plain text CustomResponseBodyKey2: ContentType: APPLICATION_JSON Content: '{"jsonfieldname": "jsonfieldvalue"}' CustomResponseBodyKey3: ContentType: TEXT_HTML Content: <html>HTML text content</html> Rules: - Name: RuleWithAWSManagedRules Priority: 0 OverrideAction: Count: {} VisibilityConfig: SampledRequestsEnabled: true CloudWatchMetricsEnabled: true MetricName: RuleWithAWSManagedRulesMetric Statement: ManagedRuleGroupStatement: VendorName: Amazon Name: AWSManagedRulesCommonRuleSet ExcludedRules: [] - Name: BlockXssAttack Priority: 1 Action: Block: CustomResponse: ResponseCode: 503 CustomResponseBodyKey: CustomResponseBodyKey1 ResponseHeaders: - Name: BlockActionHeader1Name Value: BlockActionHeader1Value - Name: BlockActionHeader2Name Value: BlockActionHeader2Value VisibilityConfig: SampledRequestsEnabled: true CloudWatchMetricsEnabled: true MetricName: BlockXssAttackMetric Statement: XssMatchStatement: FieldToMatch: AllQueryArguments: {} TextTransformations: - Priority: 1 Type: NONE

JSON

"ExampleWebACL": { "Type": "AWS::WAFv2::WebACL", "Properties": { "Name": "ExampleWebACL1", "Scope": "REGIONAL", "Description": "This is an example WebACL", "DefaultAction": { "Allow": { "CustomRequestHandling": { "InsertHeaders": [ { "Name": "AllowActionHeader1Name", "Value": "AllowActionHeader1Value" }, { "Name": "AllowActionHeader2Name", "Value": "AllowActionHeader2Value" } ] } } }, "VisibilityConfig": { "SampledRequestsEnabled": true, "CloudWatchMetricsEnabled": true, "MetricName": "ExampleWebACLMetric" }, "CustomResponseBodies": { "CustomResponseBodyKey1": { "ContentType": "TEXT_PLAIN", "Content": "this is a plain text" }, "CustomResponseBodyKey2": { "ContentType": "APPLICATION_JSON", "Content": "{\"jsonfieldname\": \"jsonfieldvalue\"}" }, "CustomResponseBodyKey3": { "ContentType": "TEXT_HTML", "Content": "<html>HTML text content</html>" } }, "Rules": [ { "Name": "RuleWithAWSManagedRules", "Priority": 0, "OverrideAction": { "Count": {} }, "VisibilityConfig": { "SampledRequestsEnabled": true, "CloudWatchMetricsEnabled": true, "MetricName": "RuleWithAWSManagedRulesMetric" }, "Statement": { "ManagedRuleGroupStatement": { "VendorName": "Amazon", "Name": "AWSManagedRulesCommonRuleSet", "ExcludedRules": [] } } }, { "Name": "BlockXssAttack", "Priority": 1, "Action": { "Block": { "CustomResponse": { "ResponseCode": 503, "CustomResponseBodyKey": "CustomResponseBodyKey1", "ResponseHeaders": [ { "Name": "BlockActionHeader1Name", "Value": "BlockActionHeader1Value" }, { "Name": "BlockActionHeader2Name", "Value": "BlockActionHeader2Value" } ] } } }, "VisibilityConfig": { "SampledRequestsEnabled": true, "CloudWatchMetricsEnabled": true, "MetricName": "BlockXssAttackMetric" }, "Statement": { "XssMatchStatement": { "FieldToMatch": { "AllQueryArguments": {} }, "TextTransformations": [ { "Priority": 1, "Type": "NONE" } ] } } } ] } }

Create a web ACL with JSON body parsing

The following shows an example web ACL specification. This example includes inspection of the web request body as JSON.

YAML

ExampleWebACL: Type: 'AWS::WAFv2::WebACL' Properties: Name: TestingJsonBody Scope: REGIONAL Description: WebACL for JsonBody Testing DefaultAction: Allow: {} VisibilityConfig: SampledRequestsEnabled: true CloudWatchMetricsEnabled: true MetricName: ExampleWebACLMetric Rules: - Name: TestJsonBodyRule Priority: 0 Action: Block: {} VisibilityConfig: SampledRequestsEnabled: true CloudWatchMetricsEnabled: true MetricName: JsonBodyMatchMetric Statement: ByteMatchStatement: FieldToMatch: JsonBody: MatchPattern: IncludedPaths: - /foo - /bar MatchScope: VALUE InvalidFallbackBehavior: MATCH PositionalConstraint: EXACTLY SearchString: BadBot TextTransformations: - Type: NONE Priority: 0

JSON

"ExampleWebACL": { "Type": "AWS::WAFv2::WebACL", "Properties": { "Name": "TestingJsonBody", "Scope": "REGIONAL", "DefaultAction": { "Allow": {} }, "Description": "WebACL for JsonBody Testing", "Rules": [ { "Name": "TestJsonBodyRule", "Priority": 1, "Statement": { "ByteMatchStatement": { "SearchString": "BadBot", "FieldToMatch": { "JsonBody": { "MatchPattern": { "IncludedPaths": [ "/foo", "/bar" ] }, "MatchScope": "VALUE", "InvalidFallbackBehavior": "MATCH" } }, "TextTransformations": [ { "Priority": 1, "Type": "NONE" } ], "PositionalConstraint": "EXACTLY" } }, "Action": { "Block": {} }, "VisibilityConfig": { "SampledRequestsEnabled": true, "CloudWatchMetricsEnabled": true, "MetricName": "JsonBodyMatchMetric" } } ], "VisibilityConfig": { "SampledRequestsEnabled": true, "CloudWatchMetricsEnabled": true, "MetricName": "TestingJsonBodyMetric" } } }