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

Static Site will incorrectly create a new Hosted Zone #93

Closed
rhboyd opened this issue Aug 3, 2019 · 2 comments · Fixed by #118
Closed

Static Site will incorrectly create a new Hosted Zone #93

rhboyd opened this issue Aug 3, 2019 · 2 comments · Fixed by #118

Comments

@rhboyd
Copy link
Contributor

rhboyd commented Aug 3, 2019

Because the example relies on an ACM Cert already existing, this would imply that the Hosted Zone already exists. The TypeScript static-site example will create a new Hosted Zone and the DNS Resolution will fail because the the new HZ is not the authority for the domain.

const zone = new route53.HostedZone(this, 'MyHostedZone', {
zoneName: props.domainName
});

@jewelsjacobs
Copy link

jewelsjacobs commented Aug 7, 2019

You can replace this with a lookup. I'm not sure the best way to implement this in the example though.

// Import Route53 existing hosted zone
const importedZone = route53.HostedZone.fromLookup(this, 'HostedZoneFromLookup', {
  domainName: props.domain
})

// Output:
new cdk.CfnOutput(this, 'HostedZoneId', { value: importedZone.hostedZoneId, exportName: 'HostedZoneID' });
new cdk.CfnOutput(this, 'ZoneName', { value: importedZone.zoneName, exportName: 'ZoneName' });

// Input props:
const hostedZoneProps = {
  hostedZoneId: cdk.Fn.importValue("HostedZoneID"),
  zoneName: cdk.Fn.importValue("ZoneName")
};

const siteDomain = props.siteSubDomain + '.' + props.domainName;

 // Route53 alias record for the CloudFront distribution
const zone = new route53.HostedZone(this, 'MyHostedZone', hostedZoneProps);
new route53.ARecord(this, 'SiteAliasRecord', {
  recordName: siteDomain,
  target: route53.AddressRecordTarget.fromAlias(new targets.CloudFrontTarget(distribution)),
  zone
});

@rhboyd
Copy link
Contributor Author

rhboyd commented Aug 7, 2019

When I added the Python example I ask the user to supply the Hosted Zone's information so we could do the lookup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants