AWS::WAFv2::RuleGroup
这是 AWS WAF 的最新版本,名为 AWS WAFV2,于 2019 年 11 月发布。有关信息(包括如何从以前的发行版迁移 AWS WAF 资源),请参阅 AWS WAF 开发人员指南。
可以使用 AWS::WAFv2::RuleGroup 定义一组规则以检查和控制 Web 请求。在将规则添加到 Web ACL 时,您可以在规则语句 RuleGroupReferenceStatement
中提供规则组的 Amazon 资源名称 (ARN) 以在 AWS::WAFv2::WebACL 中使用该组。
在创建规则组时,您可以定义一个不变的容量限制。如果更新规则组,您必须保持在容量内。这样,其他人可以重用规则组并确信满足其容量要求。
当您使用 AWS CloudFormation 管理 Web ACL 和规则组时,最多只能使用 3 个级别的嵌套规则语句。当您使用 API 和软件开发工具包时,此限制不存在。
语法
要在 AWS CloudFormation 模板中声明此实体,请使用以下语法:
JSON
{ "Type" : "AWS::WAFv2::RuleGroup", "Properties" : { "Capacity" :
Integer
, "Description" :String
, "Name" :String
, "Rules" :[ Rule, ... ]
, "Scope" :String
, "Tags" :[ Tag, ... ]
, "VisibilityConfig" :VisibilityConfig
} }
YAML
Type: AWS::WAFv2::RuleGroup Properties: Capacity:
Integer
Description:String
Name:String
Rules:- Rule
Scope:String
Tags:- Tag
VisibilityConfig:VisibilityConfig
属性
Capacity
-
该规则组所需的 Web ACL 容量单位 (WCU)。
在创建您自己的规则组时,您可以定义该单位,并且在创建后无法更改该单位。在规则组中添加或修改规则时,AWS WAF 将实施该限制。您可以使用 CheckCapacity 检查一组规则的容量。
AWS WAF 使用 WCU 计算和控制用于运行规则、规则组和 Web ACL 的运行资源。AWS WAF 以不同的方式计算每种规则类型的容量,以反映每个规则的相对成本。与使用更多处理能力的更复杂规则相比,运行成本很低的简单规则使用更少的 WCU。规则组容量在创建时是固定的,这可以帮助用户在使用规则组时计划其 Web ACL WCU 使用情况。Web ACL 的 WCU 限制为 1,500。
必需:是
类型:整数
Update requires: No interruption
Description
-
规则组的友好描述。在创建规则组后,您无法更改其描述。
必需:否
类型:字符串
最低:
1
最高:
256
模式:
^[\w+=:#@/\-,\.][\w+=:#@/\-,\.\s]+[\w+=:#@/\-,\.]$
Update requires: No interruption
Name
-
规则组的友好名称。在创建规则组后,您无法更改其名称。
必需:否
类型:字符串
最低:
1
最高:
128
模式:
^[\w\-]+$
Update requires: No interruption
Rules
-
用于指定要允许、阻止或计数的 Web 请求的规则语句。每个规则包含一个顶级语句(AWS WAF 使用该语句指定匹配的 Web 请求)以及一些参数(控制 AWS WAF 如何处理它们)。
必需:否
类型:Rule 列表
Update requires: No interruption
Scope
-
指定它用于 AWS CloudFront 分配还是区域应用程序。区域应用程序可以是 Application Load Balancer (ALB)、Amazon API Gateway REST API 或 AWS AppSync GraphQL API。有效值为
CLOUDFRONT
和REGIONAL
。注意 对于
CLOUDFRONT
,您必须在美国东部(弗吉尼亚北部)区域创建您的 WAFv2 资源us-east-1
。必需:是
类型:字符串
Update requires: No interruption
Tags
-
与 AWS 资源关联的键值对。键值对可以是您定义的任何内容。通常,标签键表示一个类别(如“environment”),标签值表示该类别中的特定值(如“test”、“development”或“production”)。您最多可以将 50 个标签添加到每个 AWS 资源中。
注意 要修改现有资源上的标签,请使用 AWS WAF 控制台或 API。借助 AWS CloudFormation,您只能在创建 AWS WAF 资源过程中向资源添加标签。
必需:否
类型:Tag 的列表
Update requires: No interruption
VisibilityConfig
-
定义并启用 Amazon CloudWatch 指标和 Web 请求采样。
必需:是
Update requires: No interruption
返回值
Ref
资源的 Ref
,其中包含资源名称、物理 ID 和范围,格式如下:name|id|scope
。
例如:my-webacl-name|1234a1a-a1b1-12a1-abcd-a123b123456|REGIONAL
Fn::GetAtt
示例
创建规则组
下面显示了一个示例规则组规范。
JSON
"Description": "Create RuleGroups", "Resources": { "SampleRuleGroup": { "Type": "AWS::WAFv2::RuleGroup", "Properties": { "Name": "SampleRuleGroup", "Scope": "REGIONAL", "Description": "SampleRuleGroup", "VisibilityConfig": { "SampledRequestsEnabled": true, "CloudWatchMetricsEnabled": true, "MetricName": "SampleRuleGroupMetrics" }, "Capacity": 1000, "Rules": [ { "Name": "RuleOne", "Priority": 1, "Action": { "Allow": {} }, "VisibilityConfig": { "SampledRequestsEnabled": true, "CloudWatchMetricsEnabled": true, "MetricName": "RuleOneMetric" }, "Statement": { "ByteMatchStatement": { "FieldToMatch": { "AllQueryArguments": {} }, "PositionalConstraint": "CONTAINS", "SearchString": "testagent", "TextTransformations": [ { "Priority": 1, "Type": "HTML_ENTITY_DECODE" } ] } } }, { "Name": "RuleTwo", "Priority": 2, "Action": { "Block": {} }, "VisibilityConfig": { "SampledRequestsEnabled": true, "CloudWatchMetricsEnabled": true, "MetricName": "RuleTwoMetric" }, "Statement": { "ByteMatchStatement": { "FieldToMatch": { "SingleHeader": { "Name": "haystack" } }, "PositionalConstraint": "CONTAINS", "SearchString": "badbot", "TextTransformations": [ { "Priority": 0, "Type": "NONE" } ] } } }, { "Name": "RuleThree", "Priority": 3, "Action": { "Count": {} }, "VisibilityConfig": { "SampledRequestsEnabled": true, "CloudWatchMetricsEnabled": true, "MetricName": "RuleThreeMetric" }, "Statement": { "ByteMatchStatement": { "FieldToMatch": { "Body": {} }, "PositionalConstraint": "CONTAINS", "SearchString": "RegionOne", "TextTransformations": [ { "Priority": 0, "Type": "HTML_ENTITY_DECODE" } ] } } }, { "Name": "RuleFour", "Priority": 4, "Action": { "Allow": {} }, "VisibilityConfig": { "SampledRequestsEnabled": true, "CloudWatchMetricsEnabled": true, "MetricName": "RuleFourMetric" }, "Statement": { "SizeConstraintStatement": { "ComparisonOperator": "GT", "Size": 1000, "FieldToMatch": { "UriPath": {} }, "TextTransformations": [ { "Priority": 0, "Type": "NONE" } ] } } } ] } } }
YAML
Description: Create RuleGroups Resources: SampleRuleGroup: Type: 'AWS::WAFv2::RuleGroup' Properties: Name: SampleRuleGroup Scope: REGIONAL Description: SampleRuleGroup VisibilityConfig: SampledRequestsEnabled: true CloudWatchMetricsEnabled: true MetricName: SampleRuleGroupMetrics Capacity: 1000 Rules: - Name: RuleOne Priority: 1 Action: Allow: {} VisibilityConfig: SampledRequestsEnabled: true CloudWatchMetricsEnabled: true MetricName: RuleOneMetric Statement: ByteMatchStatement: FieldToMatch: AllQueryArguments: {} PositionalConstraint: CONTAINS SearchString: testagent TextTransformations: - Priority: 1 Type: HTML_ENTITY_DECODE - Name: RuleTwo Priority: 2 Action: Block: {} VisibilityConfig: SampledRequestsEnabled: true CloudWatchMetricsEnabled: true MetricName: RuleTwoMetric Statement: ByteMatchStatement: FieldToMatch: SingleHeader: Name: haystack PositionalConstraint: CONTAINS SearchString: badbot TextTransformations: - Priority: 0 Type: NONE - Name: RuleThree Priority: 3 Action: Count: {} VisibilityConfig: SampledRequestsEnabled: true CloudWatchMetricsEnabled: true MetricName: RuleThreeMetric Statement: ByteMatchStatement: FieldToMatch: Body: {} PositionalConstraint: CONTAINS SearchString: RegionOne TextTransformations: - Priority: 0 Type: HTML_ENTITY_DECODE - Name: RuleFour Priority: 4 Action: Allow: {} VisibilityConfig: SampledRequestsEnabled: true CloudWatchMetricsEnabled: true MetricName: RuleFourMetric Statement: SizeConstraintStatement: ComparisonOperator: GT Size: 1000 FieldToMatch: UriPath: {} TextTransformations: - Priority: 0 Type: NONE