AWS::WAF::IPSet
这是 AWS WAF Classic 文档。有关更多信息,请参阅开发人员指南中的 AWS WAF Classic。
有关最新版本的 AWS WAF,请使用 AWS WAFV2 API 并参阅 AWS WAF 开发人员指南。对于最新版本,AWS WAF 具有一组用于区域和全球范围的终端节点。
包含以无类域间路由 (CIDR) 表示法指定的一个或多个 IP 地址或 IP 地址块。AWS WAF 支持以下 IPv4 地址范围:/8 和任何介于 /16 到 /32 之间的范围。AWS WAF 支持以下 IPv6 地址范围:/24、/32、/48、/56、/64 和 /128。
要指定单个 IP 地址,您可以指定由四部分组成的 IP 地址,后跟 /32
,例如,192.0.2.0/32。要阻止一系列 IP 地址,您可以指定 /8 或 /16 到 /32 之间的任何范围(对于 IPv4),或者指定 /24、/32、/48、/56、/64
或 /128(对于 IPv6)。有关 CIDR 表示法的更多信息,请参阅维基百科条目无类域间路由
语法
要在 AWS CloudFormation 模板中声明此实体,请使用以下语法:
JSON
{ "Type" : "AWS::WAF::IPSet", "Properties" : { "IPSetDescriptors" :
[ IPSetDescriptor, ... ]
, "Name" :String
} }
YAML
Type: AWS::WAF::IPSet Properties: IPSetDescriptors:
- IPSetDescriptor
Name:String
属性
IPSetDescriptors
-
Web 请求来自的 IP 地址类型(
IPV4
或IPV6
)和 IP 地址范围(以 CIDR 表示)。如果WebACL
与 CloudFront 分配相关联,并且查看器未使用 HTTP 代理或负载均衡器发送请求,则这是 CloudFront 访问日志中 c-ip 字段的值。必需:否
类型:IPSetDescriptor 的列表
Update requires: No interruption
Name
-
IPSet
的易记名称或描述。您在创建IPSet
后无法更改其名称。必需:是
类型:字符串
最低:
1
最高:
128
模式:
.*\S.*
Update requires: Replacement
返回值
Ref
在将此资源的逻辑 ID 传递给内部 Ref
函数时,Ref
返回资源的物理 ID,例如 1234a1a-a1b1-12a1-abcd-a123b123456。
For more information about using the Ref
function, see Ref.
示例
定义 IP 地址
下面的示例为一条 Web 访问控制列表 (ACL) 规则定义了一组 IP 地址。
JSON
"MyIPSetBlacklist": { "Type": "AWS::WAF::IPSet", "Properties": { "Name": "IPSet for blacklisted IP adresses", "IPSetDescriptors": [ { "Type" : "IPV4", "Value" : "192.0.2.44/32" }, { "Type" : "IPV4", "Value" : "192.0.7.0/24" } ] } }
YAML
MyIPSetBlacklist: Type: "AWS::WAF::IPSet" Properties: Name: "IPSet for blacklisted IP adresses" IPSetDescriptors: - Type: "IPV4" Value: "192.0.2.44/32" - Type: "IPV4" Value: "192.0.7.0/24"
关联 IPSet 与 Web ACL 规则
下面的示例将 MyIPSetBlacklist
IP 集关联到一条 Web ACL 规则。
JSON
"MyIPSetRule" : { "Type": "AWS::WAF::Rule", "Properties": { "Name": "MyIPSetRule", "MetricName" : "MyIPSetRule", "Predicates": [ { "DataId" : { "Ref" : "MyIPSetBlacklist" }, "Negated" : false, "Type" : "IPMatch" } ] } }
YAML
MyIPSetRule: Type: "AWS::WAF::Rule" Properties: Name: "MyIPSetRule" MetricName: "MyIPSetRule" Predicates: - DataId: Ref: "MyIPSetBlacklist" Negated: false Type: "IPMatch"
创建 Web ACL
以下示例将 MyIPSetRule
规则关联到一个 Web ACL。此 Web ACL 允许来自所有 IP 地址的请求,但 MyIPSetRule
中定义的地址除外。
JSON
"MyWebACL": { "Type": "AWS::WAF::WebACL", "Properties": { "Name": "WebACL to block blacklisted IP addresses", "DefaultAction": { "Type": "ALLOW" }, "MetricName" : "MyWebACL", "Rules": [ { "Action" : { "Type" : "BLOCK" }, "Priority" : 1, "RuleId" : { "Ref" : "MyIPSetRule" } } ] } }
YAML
MyWebACL: Type: "AWS::WAF::WebACL" Properties: Name: "WebACL to block blacklisted IP addresses" DefaultAction: Type: "ALLOW" MetricName: "MyWebACL" Rules: - Action: Type: "BLOCK" Priority: 1 RuleId: Ref: "MyIPSetRule"