-
Notifications
You must be signed in to change notification settings - Fork 4k
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): use same set of PublicHostedZone NameServer records between deploys #12756
Comments
The blog post you linked to seems to be accurate; given there is no CloudFormation support for reusable delegation sets, the only option currently is to use a Custom Resource. The solution in the blog post looks to be a good starting point to build off of. As an alternative, is it possible to separate out your public hosted zone(s) from the rest of your infrastructure? If the deleting + creating the hosted zone requires additional manual effort out-of-band, I would separate that out as its own component, and then you can freely set up + tear down the rest of your infrastructure without needing to update the name servers. Your mileage may vary and that approach may not work for your particular architecture and use case, but it's worth considering. |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
If possible I’d be placing this feature in the queue as it makes sense to have fixed delegation sets when using other domain registrars. Edit: I have successfully used @Pablissimo's code. The only thing I changed was to make the CallerReference unique: hosted-zone.ts// Allows CDK to use a reusable delegation set. Sourced from:
// https://pablissimo.com/1100/creating-a-route-53-public-hosted-zone-with-a-reusable-delegation-set-id-in-cdk
import {
AwsCustomResource,
AwsCustomResourcePolicy,
} from "@aws-cdk/custom-resources";
import { Construct, Fn, Names } from "@aws-cdk/core";
import {
IPublicHostedZone,
PublicHostedZone,
PublicHostedZoneProps,
} from "@aws-cdk/aws-route53";
import { PhysicalResourceId } from "@aws-cdk/custom-resources";
export interface PublicHostedZoneWithReusableDelegationSetProps
extends PublicHostedZoneProps {
delegationSetId: string;
}
export class PublicHostedZoneWithReusableDelegationSet extends Construct {
private publicHostedZone: AwsCustomResource;
private hostedZoneName: string;
constructor(
scope: Construct,
id: string,
props: PublicHostedZoneWithReusableDelegationSetProps
) {
super(scope, id);
this.hostedZoneName = props.zoneName;
const normaliseId = (id: string) => id.split("/").slice(-1)[0];
const normalisedDelegationSetId = normaliseId(props.delegationSetId);
this.publicHostedZone = new AwsCustomResource(
this,
"CreatePublicHostedZone",
{
onCreate: {
service: "Route53",
action: "createHostedZone",
parameters: {
CallerReference: Names.uniqueId(this),
Name: this.hostedZoneName,
DelegationSetId: normalisedDelegationSetId,
HostedZoneConfig: {
Comment: props.comment,
PrivateZone: false,
},
},
physicalResourceId: PhysicalResourceId.fromResponse("HostedZone.Id"),
},
policy: AwsCustomResourcePolicy.fromSdkCalls({
resources: AwsCustomResourcePolicy.ANY_RESOURCE,
}),
}
);
new AwsCustomResource(this, "DeletePublicHostedZone", {
onDelete: {
service: "Route53",
action: "deleteHostedZone",
parameters: {
Id: this.publicHostedZone.getResponseField("HostedZone.Id"),
},
},
policy: AwsCustomResourcePolicy.fromSdkCalls({
resources: AwsCustomResourcePolicy.ANY_RESOURCE,
}),
});
}
asPublicHostedZone(): IPublicHostedZone {
return PublicHostedZone.fromHostedZoneAttributes(
this,
"CreatedPublicHostedZone",
{
hostedZoneId: Fn.select(
2,
Fn.split("/", this.publicHostedZone.getResponseField("HostedZone.Id"))
),
zoneName: this.hostedZoneName,
}
);
}
} I think this is close to being ready to incorporate. It cleans up after itself fine too. |
Is this implemented, yet? I have been using the custom resource implementation as described here but the solution from @hughevans is not fully functional. Updating the stack doesn't work, as well as destroying and re-deploying it. The error log is as follows:
|
❓ General Issue
The Question
Hi! When creating a PublicHostedZone, CDK creates a new set of NameServers each time the stack is created, which then requires the NameServers to be manually updated at the domain register to point to the newly created zone. Is there any way (using CDK) to create a fixed set of NS that will be used each time the stack is created?
Environment
Other information
The text was updated successfully, but these errors were encountered: