[elbv2] support metric methods on IApplicationTargetGroup
See original GitHub issueApplicationTargetGroup.FromTargetGroupAttributes returns an IApplicationTargetGroupProxy instead of IApplicationTargetGroup, as outlined in the documentation. This class cannot be cast to ApplicationTargetGroup
Reproduction Steps
var targetGroup = (ApplicationTargetGroup) ApplicationTargetGroup.FromTargetGroupAttributes(this, "TargetGroup", new TargetGroupAttributes {
TargetGroupArn = props.TargetGroupArn,
LoadBalancerArns = props.LoadBalancerArn
});
_metric = targetGroup.MetricHttpCodeTarget(props.StatusCode);
What did you expect to happen?
IApplicationTargetGroup is cast to ApplicationTargetGroup and returns HttpCode metric
What actually happened?
On cdk synth:
Unhandled exception. System.InvalidCastException: Unable to cast object of type 'Amazon.CDK.AWS.ElasticLoadBalancingV2.IApplicationTargetGroupProxy' to type 'Amazon.CDK.AWS.ElasticLoadBalancingV2.ApplicationTargetGroup'.
Environment
- CLI Version : 1.67.0
- Framework Version: 1.67.0
- Node.js Version: v12.19.0
- OS : OSX 10.14.6
- Language (Version): .NET Core 3.1.200
Other
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:7 (3 by maintainers)
Top Results From Across the Web
aws-cdk/aws-elasticloadbalancingv2 module
'internetFacing' is 'false' // by default, which creates an internal load balancer. const lb = new elbv2.ApplicationLoadBalancer(this, 'LB', { vpc, ...
Read more >AttributeError: <class 'aws_cdk.aws_elasticloadbalancingv2 ...
IApplicationTargetGroup doesn't currently support the metric* methods, as the metrics need the load balancer name, which an imported group ...
Read more >@aws-cdk/aws-elasticloadbalancingv2 - Package Manager
acm: DaysToExpiry metric (#15424 (ff044ed); appmesh: add support for shared Meshes ... elbv2: explicitly implement IApplicationTargetGroup (#1806 (828a2d7), ...
Read more >awselasticloadbalancingv2 - Go Packages
type IApplicationLoadBalancerTarget; type IApplicationTargetGroup ... Metric // The number of load balancer capacity units (LCU) used by ...
Read more >AWS ELBv2 Best Practices - Trend Micro
Ensure ELBv2 load balancers have secure and valid security groups. ... Ensure that support for gRPC protocol is enabled for Application Load Balancers ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We can convert this to a feature request for exposing the metric methods for
IApplicationTargetGroup
. I can’t comment on or commit to a timeline when these will be added; however, pull requests are always appreciated!In my case we separated resources from deployment. This means in our CI/CD pipeline we first have a job that creates all resources (ECS Cluster, ALB, TargetGroups, DynamoDB’s etc…). Secondly all ECS services are created and deployed to the ECS cluster.
Therefor we import the TargetGroup via
ApplicationTargetGroup.fromTargetGroupAttributes
during the second (deployment) step:And register the service + add a scaling metric for requests (
scaleOnRequestCount
):Unfortunately
ApplicationTargetGroup.fromTargetGroupAttributes
only returnsIApplicationTargetGroup
and notApplicationTargetGroup
which ultimately leads to the error as seen in the snippet.I also tried to cast it but it will fail during runtime then:
Is there any clean way to get around this as of now? How to get the actual
ApplicationTargetGroup
instance?