Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(ecs): FargateService - register_load_balancer_target doesn't accept a valid listener when used with python 3.10.6 #25991

Closed
Balaji-JBC opened this issue Jun 15, 2023 · 4 comments
Labels
@aws-cdk/aws-elasticloadbalancingv2 Related to Amazon Elastic Load Balancing V2

Comments

@Balaji-JBC
Copy link

Balaji-JBC commented Jun 15, 2023

Describe the bug

I try to register load balancer target using register load balancer targets. However, I always get a jsii type error. Intellisense and aws_cdk documentation have right examples

Expected Behavior

If the listener is of valid type. It's not supposed to throw any error

Current Behavior

Even when the listener is valid the following error is thrown
TypeError: type of argument listener must be aws_cdk.aws_elasticloadbalancingv2.ApplicationListener; got jsii._reference_map.InterfaceDynamicProxy instead

Reproduction Steps

This error can be reproduced by running the example provided in the aws_cdk documentation itself

# cluster: ecs.Cluster
# task_definition: ecs.TaskDefinition
# vpc: ec2.Vpc

service = ecs.FargateService(self, "Service", cluster=cluster, task_definition=task_definition)

lb = elbv2.ApplicationLoadBalancer(self, "LB", vpc=vpc, internet_facing=True)
listener = lb.add_listener("Listener", port=80)
service.register_load_balancer_targets(
    container_name="web",
    container_port=80,
    new_target_group_id="ECS",
    listener=ecs.ListenerConfig.application_listener(listener,
        protocol=elbv2.ApplicationProtocol.HTTPS
    )
)

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.63.2

Framework Version

No response

Node.js Version

18.16.0

OS

Ubuntu 22.04

Language

Python

Language Version

3.10.6

Other information

No response

@Balaji-JBC Balaji-JBC added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 15, 2023
@github-actions github-actions bot added the @aws-cdk/aws-elasticloadbalancingv2 Related to Amazon Elastic Load Balancing V2 label Jun 15, 2023
@indrora indrora added p1 language/python Related to Python bindings language/support Related to non-typescript language bindings that aren't currently supported jsii This issue originates in jsii, or this feature must be implemented in jsii. and removed needs-triage This issue or PR still needs to be triaged. labels Jun 15, 2023
@peterwoodworth
Copy link
Contributor

peterwoodworth commented Jun 15, 2023

I can't reproduce this @Balaji-JBC, but this isn't a full snippet that will run out of the box since some of the resources aren't truly defined here.

In addition to needing to define some additional resources that this snippet doesn't really do, you'll also find that there's something missing in the snippet. I am pretty sure you need to wrap the props passed into register_load_balancer_target with the ecs.EcsTarget builder like so:

        service.register_load_balancer_targets(ecs.EcsTarget(
            container_name="web",
            container_port=80,
            new_target_group_id="ECS",
            listener=ecs.ListenerConfig.application_listener(listener,
                protocol=elbv2.ApplicationProtocol.HTTPS
            )
        ))

Let me know if this helps, and we can track this as a documentation issue. You may also want to try reinstalling your packages and making sure all the CDK versions are the same, that's a pretty odd error you got for this.

@peterwoodworth peterwoodworth added p2 documentation This is a problem with documentation. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed p1 language/python Related to Python bindings language/support Related to non-typescript language bindings that aren't currently supported labels Jun 15, 2023
@peterwoodworth peterwoodworth changed the title FargateService: register_load_balancer_target doesn't accept a valid listener (ecs): python docs don't show the necessary ecs.EcsTarget builder in generated snippet Jun 15, 2023
@Balaji-JBC
Copy link
Author

Balaji-JBC commented Jun 16, 2023

Hello @peterwoodworth . The proposed solution also didn't work. I got the same error. Here's the snippet

        https_listener = elb.ApplicationListener.from_application_listener_attributes(
            self, "HTTPSListener",
            listener_arn=https_listener_arn,
            security_group=ec2.SecurityGroup.from_security_group_id(
                self,
                "ListenerSecurityGroup",
                security_group_id=sg_id
            )
        )

        service.register_load_balancer_targets(ecs.EcsTarget(
                container_name="web",
                container_port=80,
                new_target_group_id="ECS",
                listener=ecs.ListenerConfig.application_listener(
                    https_listener,
                    protocol=elb.ApplicationProtocol.HTTPS
                ),
            )
        )

Got the same error


TypeError: type of argument listener must be aws_cdk.aws_elasticloadbalancingv2.ApplicationListener; got jsii._reference_map.Interfa
ceDynamicProxy instead

Edit: I'm using Python 3.10.6. Is that maybe causing the issue?

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jun 16, 2023
@Balaji-JBC Balaji-JBC changed the title (ecs): python docs don't show the necessary ecs.EcsTarget builder in generated snippet (ecs): FargateService - register_load_balancer_target doesn't accept a valid listener when used with python 3.10.6 Jun 16, 2023
@peterwoodworth
Copy link
Contributor

Oh, this is because you're importing the ApplicationListener, which returns an IApplicationListener. ListenerConfig.application_listener() requires the full ApplicationListener construct, so this shouldn't work

@peterwoodworth peterwoodworth removed bug This issue is a bug. p2 jsii This issue originates in jsii, or this feature must be implemented in jsii. documentation This is a problem with documentation. labels Jun 16, 2023
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-elasticloadbalancingv2 Related to Amazon Elastic Load Balancing V2
Projects
None yet
Development

No branches or pull requests

3 participants