Skip to content

Commit

Permalink
fix: missing hosted zone record with alias to cloudfront (#42)
Browse files Browse the repository at this point in the history
When a domain name is specified, the hosted zone needs an A/AAAA record that points to the cloudfront distribution. Add that.

Resolves cdklabs/construct-hub-ops#17
  • Loading branch information
Elad Ben-Israel committed May 10, 2021
1 parent 7aefc14 commit d3d068a
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 12 deletions.
10 changes: 10 additions & 0 deletions .projen/deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@
"version": "^1.100.0",
"type": "peer"
},
{
"name": "@aws-cdk/aws-route53-targets",
"version": "^1.100.0",
"type": "peer"
},
{
"name": "@aws-cdk/aws-route53",
"version": "^1.100.0",
Expand Down Expand Up @@ -200,6 +205,11 @@
"version": "^1.100.0",
"type": "runtime"
},
{
"name": "@aws-cdk/aws-route53-targets",
"version": "^1.100.0",
"type": "runtime"
},
{
"name": "@aws-cdk/aws-route53",
"version": "^1.100.0",
Expand Down
1 change: 1 addition & 0 deletions .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const project = new AwsCdkConstructLibrary({
'@aws-cdk/aws-cloudwatch',
'@aws-cdk/aws-certificatemanager',
'@aws-cdk/aws-route53',
'@aws-cdk/aws-route53-targets',
'@aws-cdk/aws-lambda',
'@aws-cdk/aws-s3',
'@aws-cdk/aws-s3-deployment',
Expand Down
2 changes: 2 additions & 0 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions src/__tests__/devapp/__snapshots__/snapshot.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/webapp/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as path from 'path';
import * as cloudfront from '@aws-cdk/aws-cloudfront';
import * as origins from '@aws-cdk/aws-cloudfront-origins';
import * as r53 from '@aws-cdk/aws-route53';
import * as r53targets from '@aws-cdk/aws-route53-targets';
import * as s3 from '@aws-cdk/aws-s3';
import * as s3deploy from '@aws-cdk/aws-s3-deployment';
import { CfnOutput, Construct } from '@aws-cdk/core';
Expand Down Expand Up @@ -29,6 +31,23 @@ export class WebApp extends Construct {
defaultRootObject: 'index.html',
});

// if we use a domain, and A records with a CloudFront alias
if (props.domain) {
// IPv4
new r53.ARecord(this, 'ARecord', {
zone: props.domain.zone,
target: r53.RecordTarget.fromAlias(new r53targets.CloudFrontTarget(this.distribution)),
comment: 'Created by the AWS CDK',
});

// IPv6
new r53.AaaaRecord(this, 'AaaaRecord', {
zone: props.domain.zone,
target: r53.RecordTarget.fromAlias(new r53targets.CloudFrontTarget(this.distribution)),
comment: 'Created by the AWS CDK',
});
}

// since `construct-hub-web` does not have an index file, we need to resolve
// a specific file inside the module.
const webappDir = path.join(__dirname, '..', '..', 'website');
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d3d068a

Please sign in to comment.