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

aws_cdk.aws_elasticloadbalancingv2: object has no attribute 'metric' #13848

Closed
alistaim opened this issue Mar 29, 2021 · 4 comments
Closed

aws_cdk.aws_elasticloadbalancingv2: object has no attribute 'metric' #13848

alistaim opened this issue Mar 29, 2021 · 4 comments
Assignees
Labels
@aws-cdk/aws-elasticloadbalancingv2 Related to Amazon Elastic Load Balancing V2 bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@alistaim
Copy link

Description

When i lookup an existing Application Load Balancer using the ARN, I can't seem to access metrics associated with it through the metric*(s) methods. I also get a default ARN returned for the object.

Reproduction Steps

alb = elbv2.ApplicationLoadBalancer.from_lookup(self, "ALB", load_balancer_arn=arn) ## arn:aws:elasticloadbalancing:us-east-1:<AccNo>:loadbalancer/app/lb-test/<Id> metric = alb.metric(elbv2.HttpCodeElb.ELB_4XX_COUNT) print(metric)

What did you expect to happen?

To get the metric object back so that I can create a Cloudwatch Alarm based off of this.

What actually happened?

I get an error saying that the object has no attribute metric :
Traceback (most recent call last): File "app.py", line 13, in <module> ALBStack(app, "ALBStack", env=deploy_env) File "/Users/mclean/code/alerts-poc/.venv/lib/python3.8/site-packages/jsii/_runtime.py", line 83, in __call__ inst = super().__call__(*args, **kwargs) File "/Users/mclean/code/alerts-poc/stacks/alb.py", line 22, in __init__ metric = alb.metric(elbv2.HttpCodeElb.ELB_4XX_COUNT) File "/Users/mclean/code/alerts-poc/.venv/lib/python3.8/site-packages/jsii/_reference_map.py", line 149, in __getattr__ raise AttributeError(f"'%s' object has no attribute '%s'" % (type_info, name)) AttributeError: '<class 'aws_cdk.core.Resource'>+<class 'aws_cdk.aws_elasticloadbalancingv2._IApplicationLoadBalancerProxy'>' object has no attribute 'metric'

Also if I do :

print(alb.load_balancer_arn)
I get back :
arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/application/my-load-balancer/50dc6c495c0c9188
which looks completely wrong and looks to be some kind of default value.

Environment

  • CDK CLI Version :1.95.1 (build ed2bbe6)
  • Framework Version: aws-cdk.aws-elasticloadbalancingv2==1.95.1
  • Node.js Version: v13.8.0
  • OS : MacOS 10.15.7
  • Language (Version): Python 3.8

This is 🐛 Bug Report

@alistaim alistaim added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 29, 2021
@peterwoodworth peterwoodworth added the @aws-cdk/aws-elasticloadbalancingv2 Related to Amazon Elastic Load Balancing V2 label Mar 29, 2021
@njlynch
Copy link
Contributor

njlynch commented Apr 9, 2021

Hi @alistaim ,

The imported load balancer is an IApplicationLoadBalancer, which doesn't currently support the metric methods. See #10850 for an existing feature request to add them.

In regards to the dummy value from the lookup, this default value arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/application/my-load-balancer/50dc6c495c0c9188 is returned when the context lookup has not yet happened or failed for whatever reason (e.g., permissions). You may need to reset your context (see https://docs.aws.amazon.com/cdk/latest/guide/context.html) to pick up the correct value.

I'm going to close this out as a duplicate of #10850. Please 👍 that issue and follow progress there.

Thanks!

@njlynch njlynch closed this as completed Apr 9, 2021
@github-actions
Copy link

github-actions bot commented Apr 9, 2021

⚠️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.

@SamStephens
Copy link
Contributor

SamStephens commented Dec 2, 2021

@njlynch unless I've misunderstood what's going on, this issue was closed in error. #10850 is about metric methods on IApplicationTargetGroup. This issue is about metric methods on IApplicationLoadBalancer.

@edisongustavo
Copy link
Contributor

This is now fixed by #23853

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 bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

5 participants