Amazon WAF Classic 使用示例 Amazon CLI - Amazon Command Line Interface
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

Amazon WAF Classic 使用示例 Amazon CLI

以下代码示例向您展示了如何使用with来执行操作和实现常见场景 Amazon WAF Classic。 Amazon Command Line Interface

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景和跨服务示例的上下文查看操作。

场景是展示如何通过在同一服务中调用多个函数来完成特定任务任务的代码示例。

每个示例都包含一个指向的链接 GitHub,您可以在其中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示如何使用 put-logging-configuration

Amazon CLI

要使用指定的 Kinesis Firehose 直播为网页 ACL ARN 创建日志配置 ARN

以下put-logging-configuration示例显示了 WAF 的 CloudFront日志配置。

aws waf put-logging-configuration \ --logging-configuration ResourceArn=arn:aws:waf::123456789012:webacl/3bffd3ed-fa2e-445e-869f-a6a7cf153fd3,LogDestinationConfigs=arn:aws:firehose:us-east-1:123456789012:deliverystream/aws-waf-logs-firehose-stream,RedactedFields=[]

输出:

{ "LoggingConfiguration": { "ResourceArn": "arn:aws:waf::123456789012:webacl/3bffd3ed-fa2e-445e-869f-a6a7cf153fd3", "LogDestinationConfigs": [ "arn:aws:firehose:us-east-1:123456789012:deliverystream/aws-waf-logs-firehose-stream" ] } }

以下代码示例演示如何使用 update-byte-match-set

Amazon CLI

更新字节匹配集

以下update-byte-match-set命令删除 a 中的 ByteMatchTuple 对象(过滤器) ByteMatchSet:

aws waf update-byte-match-set --byte-match-set-id a123fae4-b567-8e90-1234-5ab67ac8ca90 --change-token 12cs345-67cd-890b-1cd2-c3a4567d89f1 --updates Action="DELETE",ByteMatchTuple={FieldToMatch={Type="HEADER",Data="referer"},TargetString="badrefer1",TextTransformation="NONE",PositionalConstraint="CONTAINS"}

有关更多信息,请参阅 Amazon WAF 开发者指南中的使用字符串匹配条件。

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateByteMatchSet中的。

以下代码示例演示如何使用 update-ip-set

Amazon CLI

更新 IP 集

以下update-ip-set命令使用 IPv4 地址更新 IPset 并删除 IPv6 地址:

aws waf update-ip-set --ip-set-id a123fae4-b567-8e90-1234-5ab67ac8ca90 --change-token 12cs345-67cd-890b-1cd2-c3a4567d89f1 --updates Action="INSERT",IPSetDescriptor={Type="IPV4",Value="12.34.56.78/16"},Action="DELETE",IPSetDescriptor={Type="IPV6",Value="1111:0000:0000:0000:0000:0000:0000:0111/128"}

或者,您可以使用 JSON 文件来指定输入。例如:

aws waf update-ip-set --ip-set-id a123fae4-b567-8e90-1234-5ab67ac8ca90 --change-token 12cs345-67cd-890b-1cd2-c3a4567d89f1 --updates file://change.json

其中 JSON 文件的内容是:

[ { "Action": "INSERT", "IPSetDescriptor": { "Type": "IPV4", "Value": "12.34.56.78/16" } }, { "Action": "DELETE", "IPSetDescriptor": { "Type": "IPV6", "Value": "1111:0000:0000:0000:0000:0000:0000:0111/128" } } ]

有关更多信息,请参阅 Amazon WAF 开发者指南中的使用 IP 匹配条件。

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateIpSet中的。

以下代码示例演示如何使用 update-rule

Amazon CLI

更新规则

以下update-rule命令删除规则中的谓词对象:

aws waf update-rule --rule-id a123fae4-b567-8e90-1234-5ab67ac8ca90 --change-token 12cs345-67cd-890b-1cd2-c3a4567d89f1 --updates Action="DELETE",Predicate={Negated=false,Type="ByteMatch",DataId="MyByteMatchSetID"}

有关更多信息,请参阅 Amazon WAF 开发者指南中的使用规则。

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateRule中的。

以下代码示例演示如何使用 update-size-constraint-set

Amazon CLI

更新大小限制集

以下update-size-constraint-set命令删除大小约束集中的 SizeConstraint 对象(滤镜):

aws waf update-size-constraint-set --size-constraint-set-id a123fae4-b567-8e90-1234-5ab67ac8ca90 --change-token 12cs345-67cd-890b-1cd2-c3a4567d89f1 --updates Action="DELETE",SizeConstraint={FieldToMatch={Type="QUERY_STRING"},TextTransformation="NONE",ComparisonOperator="GT",Size=0}

有关更多信息,请参阅 Amazon WAF 开发者指南中的使用大小限制条件。

以下代码示例演示如何使用 update-sql-injection-match-set

Amazon CLI

更新 SQL 注入匹配集

以下update-sql-injection-match-set命令删除 SQL 注入匹配集中的 SqlInjectionMatchTuple 对象(过滤器):

aws waf update-sql-injection-match-set --sql-injection-match-set-id a123fae4-b567-8e90-1234-5ab67ac8ca90 --change-token 12cs345-67cd-890b-1cd2-c3a4567d89f1 --updates Action="DELETE",SqlInjectionMatchTuple={FieldToMatch={Type="QUERY_STRING"},TextTransformation="URL_DECODE"}

有关更多信息,请参阅 Amazon WAF 开发者指南中的使用 SQL 注入匹配条件。

以下代码示例演示如何使用 update-web-acl

Amazon CLI

更新 Web ACL

以下update-web-acl命令删除 Web ActivatedRule ACL 中的对象。

aws waf — a123fae4-b567-8e90 update-web-acl -123 web-acl-id 4-5ab67ac8ca90 — change-token 12cs345-67cd-890b-1cd2-c3a4567d89f1 — updates action= “Delete”,=' {Priority=1,= “wafrule-1-Example”,Action= {type= “Allow”},type= “Regular”} 'ActivatedRuleRuleId

输出:

{ "ChangeToken": "12cs345-67cd-890b-1cd2-c3a4567d89f1" }

有关更多信息,请参阅 WA Amazon F、Fi Amazon rewall Manager 和 Amazon Shield 高级开发者指南中的使用 Web ACL

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateWebAcl中的。

以下代码示例演示如何使用 update-xss-match-set

Amazon CLI

更新 XSS MatchSet

以下update-xss-match-set命令删除中的 XssMatchTuple 对象(滤镜) XssMatchSet:

aws waf update-xss-match-set --xss-match-set-id a123fae4-b567-8e90-1234-5ab67ac8ca90 --change-token 12cs345-67cd-890b-1cd2-c3a4567d89f1 --updates Action="DELETE",XssMatchTuple={FieldToMatch={Type="QUERY_STRING"},TextTransformation="URL_DECODE"}

有关更多信息,请参阅 Amazon WAF 开发者指南中的使用跨站点脚本匹配条件。

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateXssMatchSet中的。