Skip to content

route53: No way to alias an existing record #23048

@adam-nielsen

Description

@adam-nielsen

Describe the bug

I am trying to create a Route53 alias to an existing record.

The test code demonstrates how to do this if you create the target record in the same stack.

However if you haven't created the target record and instead need to load an existing record, there does not appear to be a way of doing so.

You could try fromValues() but it only accepts IP addresses:

new route53.ARecord(this, 'Alias', {
  zone,
  target: route53.RecordTarget.fromValues('target.example.com'),
});

[Invalid Resource Record: 'FATAL problem: ARRDATAIllegalIPv4Address (Value is not a valid IPv4 address) encountered with 'target.example.com'']

It seems it is not possible to create an alias in one stack to a Route53 record from another stack, even if both are in the same hosted zone. It can only be done via the AWS Console.

Expected Behavior

I expected fromValues() to allow me to look up a Route53 record by name, or for there to be some other way to load a Route53 record so it can be used as a target.

Current Behavior

The only current way that might work to do this - with fromValues() - only accepts IP addresses, not hostnames.

Reproduction Steps

Use the test code but have it load an existing Route53 record to use as the alias target, instead of targeting the record it just created.

Possible Solution

Either allow fromValues() to look up via hostname, or add lookup methods to Route53.ARecord and the other record classes to allow existing records to be retrieved.

I did find a workaround online, which is to pass a bind() function in instead:

new route53.ARecord(this, 'Alias', {
  zone,
  target: route53.RecordTarget.fromAlias({
    bind: () => ({
      dnsName: 'existing.example.com',
      hostedZoneId: zone.hostedZoneId,
    }),
  }),
});

However this seems a bit hacky.

Additional Information/Context

I have the target DNS entry created in a primary CDK stack, and I want to make an alias for it in a few secondary CDK stacks for other projects. This way if the IP address ever changes in the primary stack, the alias in the secondary stacks won't need to be updated, and I won't have to hard-code any IP addresses from the primary's resources in the secondary stacks.

CDK CLI Version

2.51.1 (latest docs online)

Framework Version

No response

Node.js Version

N/A (just looking at the docs, no code yet)

OS

Linux

Language

Typescript

Language Version

No response

Other information

No response

Metadata

Metadata

Labels

@aws-cdk/aws-route53Related to Amazon Route 53bugThis issue is a bug.effort/mediumMedium work item – several days of effortp1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions