-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
Describe the feature
Implement GraphqlApiDomainTarget in aws-cdk-lib/aws-route53-targets to facilitate easily configuring A records for AppSync APIs with custom domains.
Use Case
https://github.com/aws/aws-cdk/tree/main/packages/aws-cdk-lib/aws-route53-targets is missing an IAliasRecordTarget implementation for AWS AppSync GraphQL APIs. The AppSync docs suggest the use of a CNAME for custom domains, but that is not an option for me because I cannot create a CNAME at the apex of the hosted zone. Also, the Route 53 console UI supports AppSync domains as an alias target, and that should be reflected in CDK.
Proposed Solution
I am currently using the following workaround in my project:
import { GraphqlApi } from 'aws-cdk-lib/aws-appsync';
import {
AliasRecordTargetConfig,
IAliasRecordTarget,
IHostedZone,
IRecordSet,
} from 'aws-cdk-lib/aws-route53';
import { CloudFrontTarget } from 'aws-cdk-lib/aws-route53-targets';
class GraphqlApiDomainTarget implements IAliasRecordTarget {
constructor(private readonly graphqlApi: GraphqlApi) {}
public bind(_record: IRecordSet, _zone?: IHostedZone): AliasRecordTargetConfig {
return {
dnsName: this.graphqlApi.appSyncDomainName,
hostedZoneId: CloudFrontTarget.getHostedZoneId(this.graphqlApi),
};
}
}I based this implementation on the UserPoolDomainTarget, and it seems to work. Unsure if there is a different, preferable approach. Here it is in use:
new ARecord(this, 'GraphqlApiDomainARecord', {
target: RecordTarget.fromAlias(new GraphqlApiDomainTarget(myGraphqlApi)),
zone: myHostedZone,
});Other Information
No response
Acknowledgements
- I may be able to implement this feature request
- This feature might incur a breaking change
CDK version used
2.85.0
Environment details (OS name and version, etc.)
Mac OS