How can I set value to CfnWebACL.DefaultActionProperty.Allow property in WAFv2 from AWS CDK and .NET core

1.2k views Asked by At

I'm trying to create WAFv2 WebAcl service using AWS CDK. My programming language is C# (.NET Core). I'm not able to figure out how to set value of CfnWebACL.DefaultActionProperty.Allow or CfnWebACL.DefaultActionProperty.Block property as it is an object type and any value I assign to it result in runtime error.

3

There are 3 answers

1
Hannah On BEST ANSWER
 new CfnWebACL(this, "webacl", new CfnWebACLProps
{
            DefaultAction = new CfnWebACL.DefaultActionProperty
            {
                Allow = new CfnWebACL.RuleActionProperty() { Allow = true }
            },
            ...
});

This model type seems to work for me ^

0
Kamaradski On

and for the pythoneers amongst us:

some_webacl = CfnWebACL(
    self,
    'some_webacl',
    default_action=CfnWebACL.DefaultActionProperty(block={}),
    scope='REGIONAL',
    visibility_config=CfnWebACL.VisibilityConfigProperty(
        cloud_watch_metrics_enabled=True,
        metric_name=NAME_PREFIX + 'some_webacl',
        sampled_requests_enabled=True
    ),
    description=NAME_PREFIX + 'some_webacl',
    rules=[]
)
0
horizon7 On

For those using Java as a language for CDK script:

`CfnWebACL.DefaultActionProperty.builder()
                .allow(CfnWebACL.RuleActionProperty.builder().allow(TRUE).build())
                .build();`