【问题标题】:AWS CDK Python WAF Multiple IPSetsAWS CDK Python WAF 多个 IPSet
【发布时间】:2021-11-15 23:38:29
【问题描述】:

我正在使用 python 在 aws cdk 中创建多个 IPSet,我想知道是否有更好的方法在 python 中编写它。

我是这样写的:

        ip_set01 = wafv2.CfnIPSet(
        scope_=self,
        id='WAFTESTIPSET01',
        scope='REGIONAL',
        description='Block test01',
        addresses= [],
        ip_address_version="IPV4",
    )
    
    
    
    ip_set02 = wafv2.CfnIPSet(
        scope_=self,
        id='WAFTESTIPSET02',
        scope='REGIONAL',
        description='Block test02',
        addresses= [],
        ip_address_version="IPV6",
    )
    
    ip_set03 = wafv2.CfnIPSet(
        scope_=self,
        id='WAFTESTIPSET03',
        scope='REGIONAL',
        description='Block test03',
        addresses= [],
        ip_address_version="IPV4",
    )

【问题讨论】:

    标签: python amazon-web-services aws-cdk amazon-waf


    【解决方案1】:

    是的,你可以这样写:

    ip_sets = [
        wafv2.CfnIPSet(
            scope_=self,
            id=f"WAFTESTIPSET0{i}",
            scope="REGIONAL",
            description=f"Block test0{i}",
            addresses=[],
            ip_address_version="IPV4",
        )
        for i in range(1, 4)
    ]
    

    如果你真的想使用不同的ip地址版本,那么你可能需要使用地图:

    ip_map = {
        "01": "IPV4",
        "02": "IPV6",
        "03": "IPV4"
    }
    ip_sets = [
        wafv2.CfnIPSet(
            scope_=self,
            id=f"WAFTESTIPSET{key}",
            scope="REGIONAL",
            description=f"Block test{key}",
            addresses=[],
            ip_address_version=ip_map[key],
        )
        for key in ip_map
    ]
    

    【讨论】:

      猜你喜欢
      • 2021-11-16
      • 2023-04-04
      • 2021-11-18
      • 2021-10-30
      • 1970-01-01
      • 2023-01-04
      • 1970-01-01
      • 1970-01-01
      • 2021-09-08
      相关资源
      最近更新 更多