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-elasticloadbalancingv2: fromApplicationLoadBalancerAttributes broken since v2.64.0 #24397

Open
ChrisLane opened this issue Mar 1, 2023 · 9 comments
Assignees
Labels
@aws-cdk/aws-elasticloadbalancingv2 Related to Amazon Elastic Load Balancing V2 bug This issue is a bug. effort/medium Medium work item – several days of effort investigating This issue is being investigated and/or work is in progress to resolve the issue. p2

Comments

@ChrisLane
Copy link

ChrisLane commented Mar 1, 2023

Describe the bug

Since v2.64.0, I can no longer import my application load balancer by its attributes from my elastic beanstalk environment.
This was working in v2.63.2.

Expected Behavior

The code in Reproduction Steps successfully gets the application load balancer for heimdallApplicationLoadBalancer as it did in v2.63.2.

Current Behavior

The code in Reproduction Steps results in the following error when using aws-cdk v2.64.0 and above:

TypeError: Cannot read properties of undefined (reading 'startsWith')
    at parseArnShape (/home/chris/git/aws-env-setup/node_modules/aws-cdk-lib/core/lib/arn.js:1:5219)
    at Arn.split (/home/chris/git/aws-env-setup/node_modules/aws-cdk-lib/core/lib/arn.js:1:2317)
    at Object.parseLoadBalancerFullName (/home/chris/git/aws-env-setup/node_modules/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/util.js:1:2289)
    at new ImportedApplicationLoadBalancer (/home/chris/git/aws-env-setup/node_modules/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.js:1:20605)
    at ApplicationLoadBalancer.fromApplicationLoadBalancerAttributes (/home/chris/git/aws-env-setup/node_modules/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.js:1:3060)
    at new StatelessCdkStack (/home/chris/git/aws-env-setup/lib/stack/stateless-cdk-stack.js:554:77)
    at /home/chris/git/aws-env-setup/bin/app.js:62:26
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/home/chris/git/aws-env-setup/bin/app.js:25:28)
    at Module._compile (node:internal/modules/cjs/loader:1275:14)

Reproduction Steps

I need to get my application load balancer via attributes since it is created by elasticbeanstalk but not available on the CfnEnvironment object. I need to pass the load balancer to create a CloudFront origin.
Example code:

const vpc = someEc2Vpc;
const serviceSecurityGroup = someEc2SecurityGroup;
const heimdallEnv = someElasticBeanstalkCfnEnvironment;
const heimdallApplicationLoadBalancer = elbv2.ApplicationLoadBalancer.fromApplicationLoadBalancerAttributes(
    this,
    "heimdall-application-load-balancer",
    {
      vpc,
      securityGroupId: serviceSecurityGroup.securityGroupId,
      loadBalancerDnsName: heimdallEnv.attrEndpointUrl
    });

const heimdallApplicationLoadBalancerOrigin = new origins.LoadBalancerV2Origin(heimdallApplicationLoadBalancer, {
  protocolPolicy: cloudfront.OriginProtocolPolicy.HTTPS_ONLY,
  originSslProtocols: [cloudfront.OriginSslPolicy.TLS_V1_2],
  readTimeout: Duration.seconds(60)
});

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.64.0 (build fb67c77)

Framework Version

No response

Node.js Version

v19.7.0

OS

Arch Linux 6.2.1-zen1

Language

Typescript

Language Version

JavaScript

Other information

No response

@ChrisLane ChrisLane added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 1, 2023
@github-actions github-actions bot added the @aws-cdk/aws-elasticloadbalancingv2 Related to Amazon Elastic Load Balancing V2 label Mar 1, 2023
@pahud
Copy link
Contributor

pahud commented Mar 1, 2023

Probably related to #23853 as it introduced the new function parseLoadBalancerFullName() which throws in your error message. To help us better trouble-shooting, can you provide a full working sample that we can simply run the reproduce the error in our account?

@pahud pahud added p1 needs-reproduction This issue needs reproduction. effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Mar 1, 2023
@ChrisLane
Copy link
Author

Here is a zip containing the project files to reproduce the error on cdk synth

cdk-alb-import-bug-example.zip

@pahud
Copy link
Contributor

pahud commented Mar 7, 2023

Hi @ChrisLane

From what I can see, the fromApplicationLoadBalancerAttributes() method requires loadBalancerArn which is missing in your provided code. I see you have loadBalancerDnsName instead which is optional. I believe you need to specify loadBalancerArn in your sample.

And in 2.63.2 this property was required as well:

So I doubt you were able to import the ALB without passing loadBalancerArn in 2.63.2.

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed p1 needs-reproduction This issue needs reproduction. effort/medium Medium work item – several days of effort labels Mar 7, 2023
@pahud pahud self-assigned this Mar 7, 2023
@ChrisLane
Copy link
Author

ChrisLane commented Mar 7, 2023

@pahud the code in the example is taken from my production system and only slightly modified.
I have been importing the ALB using just loadBalancerDnsName for a lot of versions now and it has always worked until this new version.

I am unsure how I would get the loadBalancerArn from a elasticbeanstalk.CfnEnvironment to be able to use it in fromApplicationLoadBalancerAttributes().

If you try the example project that I linked and change the version to v2.63.2, you will see that it works.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Mar 7, 2023
@pahud
Copy link
Contributor

pahud commented Mar 15, 2023

I noticed your zip bundle are CDK codes in JS. Yes I noticed your CDK in JS with cdk v2.63.2 can synthesize but if you create a new repo with CDK in TypeScript with version v2.63.2 the loadBalancerArn is still mandatory.

Did you write your CDK code in javascript rather than typescript?

image

@pahud pahud added p2 effort/medium Medium work item – several days of effort investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Mar 15, 2023
@ChrisLane
Copy link
Author

Yes sorry, my projects are all in JavaScript. The issue template doesn't offer JavaScript as an option.

@pahud
Copy link
Contributor

pahud commented Mar 15, 2023

@ChrisLane

No problem but using TypeScript over JavaScript would allow you to have powerful type check from IDE and boost your coding performance with CDK. Is there any reason you need to us JS rather than TS in your project?

@ChrisLane
Copy link
Author

@ChrisLane

No problem but using TypeScript over JavaScript would allow you to have powerful type check from IDE and boost your coding performance with CDK. Is there any reason you need to us JS rather than TS in your project?

Unfortunately that's a limitation for my team in particular since all of our other projects are JavaScript rather than TypeScript, we try to keep everything in the same language.

@ChrisLane
Copy link
Author

I'm currently working around this issue by getting the load balancer via the fromLookup function matching against a tag instead.

elbv2.ApplicationLoadBalancer.fromLookup(
          this,
          "heimdall-application-load-balancer",
          {
            loadBalancerTags: {"elasticbeanstalk:environment-name": heimdallEnv.environmentName}
          });

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. effort/medium Medium work item – several days of effort investigating This issue is being investigated and/or work is in progress to resolve the issue. p2
Projects
None yet
Development

No branches or pull requests

2 participants