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-route53-targets: LoadBalancerTarget always appends the dualstack prefix even when not a valid option #16987

Closed
epalace510 opened this issue Oct 14, 2021 · 6 comments
Labels
@aws-cdk/aws-route53-targets bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/small Small work item – less than a day of effort p1

Comments

@epalace510
Copy link

What is the problem?

When fixing #6271 with #8747, you enforced that all load balancer targets start with the dualstack prefix. Network Load Balancers (NLBs) have 2 IP Address types you can configure, IPv4 or dualstack (this was launched late last year). The default for the property is IPv4, and the CDK definition doesn't even allow for the option to be set. When NLB is set to IPv4, it does not have a dualstack prefix you can route to. This means the generated ARecords don't work; they target a non-existent DNS record.

Reproduction Steps

I'm going to leave the class instantiation out, but you can assume this is within a construct.

this.hostedZone = new route53.HostedZone(this, "ExampleHostedZone", {
    zoneName: props.hostedZoneName,
});

this.vpc = new ec2.Vpc(this, "ExampleVPC");

this.loadBalancer = new elasticloadbalancingv2.NetworkLoadBalancer(this, "ExampleNLB", {
  vpc: this.vpc,
});

new aws-route53.ARecord(this,
  "LoadBalancerAlias",
  {
    zone: this.hostedZone,
    target: aws-route53.RecordTarget.fromAlias(
      new aws-route53-targets.LoadBalancerTarget(this.loadBalancer)
    ),
    comment: "A-Record to route traffic to the service Load Balancer",
  }
);

What did you expect to happen?

I expected a valid Alias ARecord to my NLB.

What actually happened?

The CDK incorrectly prefixed dualstack to my NLB DNS name, causing the service to be unreachable.

CDK CLI Version

1.125.0

Framework Version

No response

Node.js Version

12

OS

AmazonLinux 2

Language

Typescript

Language Version

No response

Other information

The NLB IPAddressType is a configurable property of the Cfn definition https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticloadbalancingv2-loadbalancer.html#cfn-elasticloadbalancingv2-loadbalancer-ipaddresstype

@epalace510 epalace510 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 14, 2021
@github-actions github-actions bot added the @aws-cdk/aws-route53 Related to Amazon Route 53 label Oct 14, 2021
@peterwoodworth peterwoodworth changed the title aws-route53-targets/LoadBalancerTarget: LoadBalancerTarget always appends the dualstack prefix even when not a valid option aws-route53-targets: LoadBalancerTarget always appends the dualstack prefix even when not a valid option Oct 15, 2021
@peterwoodworth peterwoodworth added effort/small Small work item – less than a day of effort p1 and removed @aws-cdk/aws-route53 Related to Amazon Route 53 needs-triage This issue or PR still needs to be triaged. labels Oct 15, 2021
@njlynch njlynch removed their assignment Oct 18, 2021
@larryboymi
Copy link

larryboymi commented Dec 1, 2021

I'm also running into this issue. @epalace510 did you figure out a workaround?

In my case I'm creating an NLB-specific version of https://github.com/aws/aws-cdk/blob/v1.134.0/packages/@aws-cdk/aws-route53-targets/lib/load-balancer-target.ts

@skyzenr
Copy link

skyzenr commented Dec 6, 2021

Same issue also with CDK v2.

@epalace510
Copy link
Author

@larryboymi I wrote a class to do what I needed. It's not my preferred solution, but it unblocked me.

import { AliasRecordTargetConfig, IAliasRecordTarget, IHostedZone, IRecordSet } from "monocdk/aws-route53";
import { NetworkLoadBalancer } from "monocdk/aws-elasticloadbalancingv2";

/**
 * Use an ELB Network Load Balancer as an alias record target.
 * This NLB specific target was written because CDK will always prepend
 * `dualstack` to the DNS name which is not always valid for NLBs.
 * https://github.com/aws/aws-cdk/issues/16987
 */
export class NetworkLoadBalancerTarget implements IAliasRecordTarget {
    private readonly loadBalancer: NetworkLoadBalancer;

    constructor(loadBalancer: NetworkLoadBalancer) {
      this.loadBalancer = loadBalancer;
    }

    /**
     * Return hosted zone ID and DNS name, usable for Route53 alias targets.
     */
    bind(_record: IRecordSet, _zone?: IHostedZone): AliasRecordTargetConfig {
      return {
        hostedZoneId: this.loadBalancer.loadBalancerCanonicalHostedZoneId,
        dnsName: this.loadBalancer.loadBalancerDnsName,
      };
    }
}

@larryboymi
Copy link

@epalace510 yep that's exactly what my class looked like

@flaksirus
Copy link

I'm facing exactly the same issue.

@github-actions
Copy link

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Dec 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-route53-targets bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

No branches or pull requests

6 participants