Skip to content

Commit

Permalink
add route53 to Network stack
Browse files Browse the repository at this point in the history
  • Loading branch information
gugzkumar committed Dec 25, 2019
1 parent e6086cf commit 1f45f33
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions .aws-infrastructure/lib/CheetSheetNetwork-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,27 @@ const SITE_SUB_DOMAIN = process.env['SITE_SUB_DOMAIN'] || '';
const SITE_DOMAIN = process.env['SITE_DOMAIN'] || '';
const AWS_ACM_CERTIFICATE_ARN = process.env['AWS_ACM_CERTIFICATE_ARN'] || '';
const ENVIRONMENT = process.env['ENVIRONMENT'] || '';
const region = process.env['AWS_DEFAULT_REGION'] || '';

export class CheetSheetNetworkStack extends cdk.Stack {

siteHostname = `${SITE_SUB_DOMAIN}.${SITE_DOMAIN}`;
siteDomainName = SITE_DOMAIN;
uiDistributionType = UI_DISTRIBUTION_TYPE;
zone:route53.IHostedZone;

constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

this.zone = route53.HostedZone.fromHostedZoneAttributes(this, 'Zone', {
hostedZoneId: AWS_ROUTE53_HOSTED_ZONE_ID,
zoneName: this.siteDomainName
});
// this.constructClientUiNetwork();
this.constructApiNetwork();

}


constructApiNetwork() {
const apiDomainName = `${SITE_SUB_DOMAIN}.api.${SITE_DOMAIN}`;
const apiRecordName = `${SITE_SUB_DOMAIN}.api`;
Expand All @@ -41,10 +48,22 @@ export class CheetSheetNetworkStack extends cdk.Stack {
});
apiDomain.addBasePathMapping(api);


const targetResource = new targets.ApiGatewayDomain(apiDomain);

const ApiDNSRecord = new route53.ARecord(this, 'ApiSiteAliasRecord', {
recordName: apiRecordName,
target: route53.AddressRecordTarget.fromAlias(
targetResource
),
zone: this.zone
});

}

constructClientUiNetwork() {
const clientUIAssetsBucketName = this.siteHostname;
const clientUIRecordName = `${SITE_SUB_DOMAIN}`;
const clientUIAssetsBucket = s3.Bucket.fromBucketName(this, 'S3ClientUIAssetsBucket' , clientUIAssetsBucketName);

const clientUIWebDistribution = new cloudfront.CloudFrontWebDistribution(this, 'CloudFrontClientUIWebDistribution', {
Expand All @@ -71,17 +90,12 @@ export class CheetSheetNetworkStack extends cdk.Stack {
});
const targetResource = new targets.CloudFrontTarget(clientUIWebDistribution);

const zone = route53.HostedZone.fromHostedZoneAttributes(this, 'Zone', {
hostedZoneId: AWS_ROUTE53_HOSTED_ZONE_ID,
zoneName: this.siteDomainName
});

const clientUIDNSRecord = new route53.ARecord(this, 'SiteAliasRecord', {
recordName: SITE_SUB_DOMAIN,
const clientUIDNSRecord = new route53.ARecord(this, 'ClientUiSiteAliasRecord', {
recordName: clientUIRecordName,
target: route53.AddressRecordTarget.fromAlias(
targetResource
),
zone
zone: this.zone
});
}

Expand Down

0 comments on commit 1f45f33

Please sign in to comment.