diff --git a/packages/@aws-cdk/aws-route53-targets/lib/api-gateway-domain-name.ts b/packages/@aws-cdk/aws-route53-targets/lib/api-gateway-domain-name.ts index c87e26568d6b8..0cc215d5c5eed 100644 --- a/packages/@aws-cdk/aws-route53-targets/lib/api-gateway-domain-name.ts +++ b/packages/@aws-cdk/aws-route53-targets/lib/api-gateway-domain-name.ts @@ -26,7 +26,7 @@ export class ApiGatewayDomain implements route53.IAliasRecordTarget { * `ApiGatewayDomain` class. */ export class ApiGateway extends ApiGatewayDomain { - constructor(api: apig.RestApi) { + constructor(api: apig.RestApiBase) { if (!api.domainName) { throw new Error('API does not define a default domain name'); } diff --git a/packages/@aws-cdk/aws-route53-targets/test/apigateway-target.test.ts b/packages/@aws-cdk/aws-route53-targets/test/apigateway-target.test.ts index e62c87b59c385..5658a1f56323a 100644 --- a/packages/@aws-cdk/aws-route53-targets/test/apigateway-target.test.ts +++ b/packages/@aws-cdk/aws-route53-targets/test/apigateway-target.test.ts @@ -106,3 +106,51 @@ test('fails if an ApiGateway is used with an API that does not define a domain n }); }).toThrow(/API does not define a default domain name/); }); + +test('targets.ApiGateway accepts a SpecRestApi', () => { + // GIVEN + const stack = new Stack(); + const cert = new acm.Certificate(stack, 'cert', { domainName: 'example.com' }); + const api = new apigw.SpecRestApi(stack, 'api', { + domainName: { + domainName: 'example.com', + certificate: cert, + }, + apiDefinition: apigw.ApiDefinition.fromInline({ + key1: 'val1', + }), + }); + const zone = new route53.HostedZone(stack, 'zone', { + zoneName: 'example.com', + }); + api.root.addMethod('GET'); + + // WHEN + new route53.ARecord(stack, 'A', { + zone, + target: route53.RecordTarget.fromAlias(new targets.ApiGateway(api)), + }); + + // THEN + expectStack(stack).to(haveResource('AWS::Route53::RecordSet', { + Name: 'example.com.', + Type: 'A', + AliasTarget: { + DNSName: { + 'Fn::GetAtt': [ + 'apiCustomDomain64773C4F', + 'RegionalDomainName', + ], + }, + HostedZoneId: { + 'Fn::GetAtt': [ + 'apiCustomDomain64773C4F', + 'RegionalHostedZoneId', + ], + }, + }, + HostedZoneId: { + Ref: 'zoneEB40FF1E', + }, + })); +}); \ No newline at end of file