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

Create alias record in route53 #36

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)),
});
}
}
Loading