Skip to content

Commit

Permalink
Create alias record in route53
Browse files Browse the repository at this point in the history
  • Loading branch information
NChitty committed Mar 20, 2024
1 parent ba3752e commit a3e281b
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions cdk/lib/application-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import path = require('path');
import { TableV2 } from 'aws-cdk-lib/aws-dynamodb';
import { Certificate, CertificateValidation } from 'aws-cdk-lib/aws-certificatemanager';
import { Role } from 'aws-cdk-lib/aws-iam';
import { CrossAccountZoneDelegationRecord, PublicHostedZone } from 'aws-cdk-lib/aws-route53';
import {
ARecord,
CrossAccountZoneDelegationRecord,
PublicHostedZone,
RecordTarget,
} from 'aws-cdk-lib/aws-route53';
import { ApiGateway } from 'aws-cdk-lib/aws-route53-targets';

export interface ApplicationLayerStackProps extends StackProps {
readonly delegationRole: Role;
Expand Down Expand Up @@ -65,19 +71,24 @@ export default class ApplicationLayerStack extends Stack {
delegationRole: props.delegationRole,
});

const api = new LambdaRestApi(this, 'MealPlannerApi', {
handler,
proxy: true,
});

const domainName = 'api.'.concat(props.domain);
const certificate = new Certificate(this, 'ApiDomainCertificate', {
domainName,
validation: CertificateValidation.fromDns(hostedZone),
});
api.addDomainName('ApiDomain', {
domainName,
certificate,
const api = new LambdaRestApi(this, 'MealPlannerApi', {
handler,
proxy: true,
domainName: {
domainName,
certificate,
},
});

new ARecord(this, 'ApiAliasRecord', {
zone: hostedZone,
recordName: 'api',
target: RecordTarget.fromAlias(new ApiGateway(api)),
});
}
}

0 comments on commit a3e281b

Please sign in to comment.