amazon-web-services - 使用 CloudFormation 从 WAFv2 创建 WebACL
问题描述
我正在尝试使用 cloudformation 创建一个 WebACL,以保护应用程序 API 免受滥用,其想法是在 5 分钟内将 API 访问限制为最多 100 个 IP 请求。
为此,我必须使用 WAFv2,因为第一个版本似乎只支持:
- 静态黑名单
- 字节匹配
- 尺寸限制
- 跨站脚本
- SQLi
WAFv2 文档: https ://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-wafv2-webacl.html
我写了这个作为例子:
AWSTemplateFormatVersion: 2010-09-09
Resources:
WebACL:
Type: 'AWS::WAFv2::WebACL'
Properties:
Name: WebAclLimit100
Scope: "REGIONAL"
DefaultAction:
Type: ALLOW
VisibilityConfig:
SampledRequestsEnabled: true
CloudWatchMetricsEnabled: true
MetricName: WebAcLimit100
但是,当我尝试将其上传到 CloudFormation 时,创建失败并显示以下消息:
模型验证失败(#: extraneous key [Type] is not allowed)
我认为问题出在以下几行:
DefaultAction:
Type: ALLOW
但是我不知道如何分配 DefaultAction 而不会在 CloudFormation 上失败,我尝试了很多次(当然不同)并且找不到正确的方法。互联网上没有 WAFv2 的示例,第一版 WAF 的语法似乎不兼容 :(
解决方案
您需要更改“DefaultAction”,因为这需要 JSON 值:请按照此处的示例部分操作 WAFv2 模板
AWSTemplateFormatVersion: 2010-09-09
Resources:
WebACL:
Type: 'AWS::WAFv2::WebACL'
Properties:
Name: WebAclLimit100
Scope: "REGIONAL"
DefaultAction:
Allow: {}
VisibilityConfig:
SampledRequestsEnabled: true
CloudWatchMetricsEnabled: true
MetricName: WebAcLimit100
推荐阅读
- android - 如何获取不在 ListView 可见部分的适配器类中的视图?- 科特林
- html - word-break: 断词在 pre 标记内失败
- reactjs - Ant Design Popconfirm 在 [ENTER] 上确认?
- java - 对 PostgreSQL 数据库使用 getClob() 的 getString() 的潜在限制
- visual-studio-code - 如何将变量值输入到 launch.json 配置?
- android - 如何向每个可渲染视图的 TextView 添加不同的文本
- flask - 烧瓶 500/404 错误
- c++ - 这不是《The C++ Programming Language(4 ed)》一书中的错误吗?
- python - 如何创建一个要求用户输入实例化的类
- appium-android - 使用 TouchAction 滚动 Appium