aws / aws/aws-cdk

aws-elasticloadbalancingv2: fromApplicationLoadBalancerAttributes broken since v2.64.0

Open
#24,397 9 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-elasticloadbalancingv2 bug effort/medium p3
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### 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:
```txt
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 ()
at Object. (/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:
```javascript
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_

Contributor guide

Open the contributing guide

Research direction

Start with the fromApplicationLoadBalancerAttributes reproduction and the stack trace through aws-elasticloadbalancingv2/lib/alb/application-load-balancer.js, shared/util.js, and core/lib/arn.js. Compare behavior between v2.63.2 and v2.64.0, then confirm that importing the Elastic Beanstalk load balancer by loadBalancerDnsName succeeds and can be passed to LoadBalancerV2Origin.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript, typescript
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.