首页 > 解决方案 > 使用 Troposphere 在 cloudformation 模板中配置 WAF(Web 应用程序防火墙)

问题描述

我想创建 WAF 并将其附加到我的负载均衡器。

我需要附加哪些资源和参数来创建 WAF,有什么例子吗,你可以建议我吗?

我尝试过这种方式,但每个规则集都使用 cloudformation 模板失败。

MyWebACL = t.add_resource(
    WebACL(
        "MyWebACL",
        Name=Ref(WebACLName),
        DefaultAction=Action(
            Type="ALLOW"
        ),
        Rules=[
            Rules(
                Action=Action(
                    Type="BLOCK"
                ),
                Priority=1,
                RuleId=Ref(ManualIPBlockRule)
            ),
            Rules(
                Action=Action(
                    Type="COUNT"
                ),
                Priority=2,
                RuleId=Ref(SizeMatchRule)
            ),
            Rules(
                Action=Action(
                    Type="BLOCK"
                ),
                Priority=3,
                RuleId=Ref(SqliRule)
            ),
            Rules(
                Action=Action(
                    Type="BLOCK"
                ),
                Priority=4,
                RuleId=Ref(XssRule)
            )
        ],
        MetricName=(),
    ))

这是我的一个示例规则:

SizeMatchRule = t.add_resource(
    Rule(
        "SizeMatchRule",
        Name=Join("", [Ref(WebACLName), "LargeBodyMatchRule"]),
        MetricName=Join("", [Ref(WebACLName), "DetectLargeBody"]),
        Predicates=[
            Predicates(
                DataId=Ref(SizeMatchSet),
                Type="SizeConstraint",
                Negated=False
            )
        ]
    ))

有什么建议和参考让我知道吗?

标签: amazon-web-servicesamazon-cloudformationweb-application-firewalltroposphere

解决方案


推荐阅读