cdk-ecs-service-extensions icon indicating copy to clipboard operation
cdk-ecs-service-extensions copied to clipboard

Question: Get underlying Load Balancer from `HttpLoadBalancerExtension`

Open expertcoder opened this issue 1 year ago • 1 comments

Hi, I have the following CDK

const httpLoadBalancerExtension = new HttpLoadBalancerExtension();
serviceDescription.add(httpLoadBalancerExtension);

new cloudfront.Distribution(this, id + 'Distribution', {
    defaultBehavior: {
        origin: new origins.LoadBalancerV2Origin(httpLoadBalancerExtension.loadBalancer),
        .....

I want to create a CloudFront distrubution using the Load Balancer as an origin, however the loadBalancer property of HttpLoadBalancerExtension is private, and I cant see any other methods which would allow access to loadBalancer.

Woundn't the CDK code above be a legitimate reason to need access to the underlying Load Balancer?

How would I acheive what I am trying to do?

Thanks for your time.

expertcoder avatar May 11 '23 12:05 expertcoder

you can try to get the loadBalancerArn from the service:

    exampleServiceDescription.add(new HttpLoadBalancerExtension());
    const exampleService = new Service(this, "example", {
      environment: environment,
      serviceDescription: exampleServiceDescription,
    });
    const alb = ApplicationLoadBalancer.fromLookup(this, "ImportedAlb", {
      loadBalancerArn: exampleService.targetGroup?.loadBalancerArns[0],
    });

jcode-hub avatar Aug 16 '23 10:08 jcode-hub