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

route53: No way to alias an existing record #23048

Closed
adam-nielsen opened this issue Nov 23, 2022 · 8 comments · Fixed by #29565, rwlxxvii/containers#124 or rwlxxvii/containers#140 · May be fixed by NOUIY/aws-solutions-constructs#99 or NOUIY/aws-solutions-constructs#101
Assignees
Labels
@aws-cdk/aws-route53 Related to Amazon Route 53 bug This issue is a bug. effort/medium Medium work item – several days of effort p1

Comments

@adam-nielsen
Copy link

adam-nielsen commented Nov 23, 2022

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

@adam-nielsen adam-nielsen added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 23, 2022
@github-actions github-actions bot added the @aws-cdk/aws-route53 Related to Amazon Route 53 label Nov 23, 2022
@pahud
Copy link
Contributor

pahud commented Nov 23, 2022

Hi @adam-nielsen

Please check out my sample below.

At this moment it is possible to create an Alias ARecord to an existing route53 record set as long as the existing one is created by CDK. However, if the existing record set is created outsides of CDK, it seems not possible at this moment. Are you trying to create an alias to an existing target record set created outsides of CDK(e.g. manually created)?

const zone = new route53.HostedZone(stack, 'Zone', {
  zoneName: 'demo.com',
});

const record = new route53.RecordSet(stack, 'target', {
  zone,
  recordName: 'target.demo.com',
  recordType: route53.RecordType.A,
  target: route53.RecordTarget.fromIpAddresses('1.2.3.4'),
});


// alias test.demo.com to the record set of 'target.demo.com'
new route53.ARecord(stack, 'Alias', {
  zone,
  recordName: 'test.demo.com',
  target: route53.RecordTarget.fromAlias(new targets.Route53RecordTarget(record)),
});

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Nov 23, 2022
@pahud pahud self-assigned this Nov 23, 2022
@adam-nielsen
Copy link
Author

Hi @pahud, yes the existing record has been created manually, so I need to somehow load it into my CDK stack, in order to pass it to Route53RecordTarget.

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

pahud commented Nov 28, 2022

I think we probably need a construct method like

route53.ARecord.fromAttributes(...) 

to import existing ARecords. I am making this as P2 but any PRs from the community would be highly appreciated!

@pahud pahud added p2 effort/medium Medium work item – several days of effort labels Nov 28, 2022
@czabriskie
Copy link

I need this functionality too.

@raveenplgithub
Copy link

+1

@pahud
Copy link
Contributor

pahud commented Aug 15, 2023

please help us 👍 on the original issue post rather than +1 in the comments.

According to the contributing guide, any P2 issue with 20 or more +1s will be automatically upgraded from P2 to P1.

@github-actions github-actions bot added p1 and removed p2 labels Feb 11, 2024
Copy link

This issue has received a significant amount of attention so we are automatically upgrading its priority. A member of the community will see the re-prioritization and provide an update on the issue.

@shikha372 shikha372 self-assigned this Mar 7, 2024
@mergify mergify bot closed this as completed in #29565 Apr 26, 2024
mergify bot pushed a commit that referenced this issue Apr 26, 2024
…as ARecord target (#29565)

### Issue # (if applicable)

Closes #23048.

### Reason for this change

Currently an existing A record created outside of CDK cannot be registered as an Alias Target under a new A record, while this is possible through AWS console.

### Description of changes

Introduces new function under class Arecord which will take input as existing record DNS name and then register it as an alias target under new Arecord. This way user will be able to alias an existing record (for type ARecord only). 

### Description of how you validated changes

- Added Unit tests to validate new A record is created with an alias target passed through new function
- Added Integration test for the alias target validation in template and after deployment to account.


### Checklist

- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment