question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cfn2ts: some property types are parsed as interfaces instead of structs

See original GitHub issue

Using the python cdk, attempting to create a Web ACL with an IP whitelisting rule, but found that creating Web ACL rule properties does not work when trying to define an IP Set. I receive an error stating: TypeError: Protocols cannot be instantiated

Reproduction Steps

       # Working rule prop, with aws managed rule group
       rule_sql = wafv2.CfnWebACL.RuleProperty(
            name='AWS-AWSManagedRulesSQLRuleSet',
            statement=wafv2.CfnWebACL.StatementOneProperty(
                managed_rule_group_statement=wafv2.CfnWebACL.ManagedRuleGroupStatementProperty(
                    vendor_name='AWS',
                    name='AWSManagedRulesSQLRuleSet'
                )
            ),
            visibility_config=wafv2.CfnWebACL.VisibilityConfigProperty(
                sampled_requests_enabled=True,
                cloud_watch_metrics_enabled=True,
                metric_name='AWS-AWSManagedRulesSQLRuleSet'
            ),
            priority=0,
        )

        # Non-working rule prop, with IP set reference
        rule_ip = wafv2.CfnWebACL.RuleProperty(
            name='IPRule',
            statement=wafv2.CfnWebACL.StatementOneProperty(
                ip_set_reference_statement=wafv2.CfnWebACL.IPSetReferenceStatementProperty(
                    arn='myArn'
                )
            ),
            visibility_config=wafv2.CfnWebACL.VisibilityConfigProperty(
                sampled_requests_enabled=True,
                cloud_watch_metrics_enabled=True,
                metric_name='IPRule'
            ),
            priority=0,
        )

Error Log

When synthing templates, this error is received:

File “…\infra\cdk.env\lib\site-packages\jsii_runtime.py”, line 66, in call inst = super().call(*args, **kwargs) File “…\infra\cdk\stacks\stacks_lib\static_site_hosting.py”, line 56, in init arn=‘myArn’ File “…\infra\cdk.env\lib\site-packages\typing_extensions.py”, line 1545, in _no_init raise TypeError(‘Protocols cannot be instantiated’) TypeError: Protocols cannot be instantiated

Environment

  • CLI Version :
  • Framework Version: 1.27
  • OS : Windows
  • Language : Python

Other

Linked somewhat to: https://github.com/aws/aws-cdk/issues/6056


This is 🐛 Bug Report

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:12
  • Comments:20 (4 by maintainers)

github_iconTop GitHub Comments

14reactions
KyleMuellerPFGcommented, Mar 10, 2020

As a workaround, I was able to implement the IPSetReferenceStatementProperty interface myself in python like so:

        @jsii.implements(wafv2.CfnRuleGroup.IPSetReferenceStatementProperty)
        class IPSetReferenceStatement:
            @property
            def arn(self):
                return self._arn

            @arn.setter
            def arn(self, value):
                self._arn = value

And then reference that new class instead:

        ip_set_ref_stmnt = IPSetReferenceStatement()
        ip_set_ref_stmnt.arn = whitelisted_ip_set.attr_arn

        # Non-working rule prop, with IP set reference
        whitelisted_ip_set_rule = wafv2.CfnWebACL.RuleProperty(
            name='AllowedIPsRule',
            statement=wafv2.CfnWebACL.StatementOneProperty(
                ip_set_reference_statement=ip_set_ref_stmnt
            ),
            visibility_config=wafv2.CfnWebACL.VisibilityConfigProperty(
                sampled_requests_enabled=True,
                cloud_watch_metrics_enabled=True,
                metric_name='AllowedIPsRule'
            ),
            priority=0,
        )

At which point, I am able to CDK synth the template, and it captures the proper reference to the IP Set Reference Statement.

1reaction
CarlosDominguescommented, Feb 5, 2021

Was bitten by this today, thanks a lot @KyleMuellerPFG!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should I declare my property as from type Class or Interface?
Its best to use Interfaces when designing properties/parameters that take a particular type but can take any version of that type.
Read more >
Accept Interfaces Return Structs | TutorialEdge.net
In this article, we are going to discuss the benefits of accepting interfaces in your code and returning structs.
Read more >
Exploring structs and interfaces in Go - LogRocket Blog
In this article, we'll focus on struct and interface types in Go. ... To explore some of its features, let us go ahead...
Read more >
QFace IDL Syntax | Qt Interface Framework 6.4.2
Properties carry data about interfaces and structures: syntax elements allow you to describe some attributes of the data. A property can be of...
Read more >
Package Diff: @aws-cdk/cdk @ 0.31.0 .. 0.32.0
"summary": "A String type that describes the output value. ... + "summary": "Turn an arbitrary structure potentially containing Tokens into a JSON string....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found