1

I am trying to create an AWS Gateway Load Balancer configuration in AWS CDK (python). I already have a working version in Cloud Formation. The synth step is failing, seemingly, because CDK is not recognizing a "list" as a Sequence.

Below is the key bit of python. Note that I'm using L1 constructs since there do not yet seem to be L2 constructs for GWLB.

        gwlb = elbv2.CfnLoadBalancer(
            self,
            "GatewayLoadBalancer",
            name=f"GWLB-{self.stack_name}",
            type="gateway",
            subnets=gwlb_subnet_ids,
            scheme="internal",
            load_balancer_attributes=[
                elbv2.CfnLoadBalancer.LoadBalancerAttributeProperty(
                    key="load_balancing.cross_zone.enabled", value="true"
                )
            ],
        )

        gw_endpoint_service = ec2.CfnVPCEndpointService(
            self,
            "VPCEndpointService",
            acceptance_required=False,
            gateway_load_balancer_arns=[gwlb.get_att("Arn")],
        )

When I run the synth, I get this error:

  File "/Users/pmryan/.pyenv/versions/3.8.12/lib/python3.8/site-packages/typeguard/__init__.py", line 757, in check_type
    checker_func(argname, value, expected_type, memo)
  File "/Users/pmryan/.pyenv/versions/3.8.12/lib/python3.8/site-packages/typeguard/__init__.py", line 558, in check_union
    raise TypeError('type of {} must be one of ({}); got {} instead'.
TypeError: type of argument gateway_load_balancer_arns must be one of (Sequence[str], NoneType); got list instead

Wondering if this is a CDK bug. In every other CDK construct, I can pass a python list to an argument that expects a Sequence.

Pat
  • 109
  • 4

1 Answers1

1

Figured it out. I had to go back and reimplement it in typescript before I could go back and fix the python. The key is that I have to send a "ref" as the value in the list of load balancers. The code below sythesizes correctly.

        gwlb = elbv2.CfnLoadBalancer(
            self,
            "GatewayLoadBalancer",
            name=f"GWLB-{self.stack_name}",
            type="gateway",
            subnets=gwlb_subnet_ids,
            scheme="internal",
            load_balancer_attributes=[
                elbv2.CfnLoadBalancer.LoadBalancerAttributeProperty(
                    key="load_balancing.cross_zone.enabled", value="true"
                )
            ],
        )

        gw_endpoint_service = ec2.CfnVPCEndpointService(
            self,
            "VPCEndpointService",
            acceptance_required=False,
            gateway_load_balancer_arns=[gwlb.ref],  # <-- FIXED
        )
Pat
  • 109
  • 4