Skip to content

Commit 20071bb

Browse files
authored
fix(route53-targets): ApiGateway does not accept RestApiBase (#16610)
Closes #16227. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent e84efd9 commit 20071bb

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

Diff for: packages/@aws-cdk/aws-route53-targets/lib/api-gateway-domain-name.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class ApiGatewayDomain implements route53.IAliasRecordTarget {
2626
* `ApiGatewayDomain` class.
2727
*/
2828
export class ApiGateway extends ApiGatewayDomain {
29-
constructor(api: apig.RestApi) {
29+
constructor(api: apig.RestApiBase) {
3030
if (!api.domainName) {
3131
throw new Error('API does not define a default domain name');
3232
}

Diff for: packages/@aws-cdk/aws-route53-targets/test/apigateway-target.test.ts

+48
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,51 @@ test('fails if an ApiGateway is used with an API that does not define a domain n
106106
});
107107
}).toThrow(/API does not define a default domain name/);
108108
});
109+
110+
test('targets.ApiGateway accepts a SpecRestApi', () => {
111+
// GIVEN
112+
const stack = new Stack();
113+
const cert = new acm.Certificate(stack, 'cert', { domainName: 'example.com' });
114+
const api = new apigw.SpecRestApi(stack, 'api', {
115+
domainName: {
116+
domainName: 'example.com',
117+
certificate: cert,
118+
},
119+
apiDefinition: apigw.ApiDefinition.fromInline({
120+
key1: 'val1',
121+
}),
122+
});
123+
const zone = new route53.HostedZone(stack, 'zone', {
124+
zoneName: 'example.com',
125+
});
126+
api.root.addMethod('GET');
127+
128+
// WHEN
129+
new route53.ARecord(stack, 'A', {
130+
zone,
131+
target: route53.RecordTarget.fromAlias(new targets.ApiGateway(api)),
132+
});
133+
134+
// THEN
135+
expectStack(stack).to(haveResource('AWS::Route53::RecordSet', {
136+
Name: 'example.com.',
137+
Type: 'A',
138+
AliasTarget: {
139+
DNSName: {
140+
'Fn::GetAtt': [
141+
'apiCustomDomain64773C4F',
142+
'RegionalDomainName',
143+
],
144+
},
145+
HostedZoneId: {
146+
'Fn::GetAtt': [
147+
'apiCustomDomain64773C4F',
148+
'RegionalHostedZoneId',
149+
],
150+
},
151+
},
152+
HostedZoneId: {
153+
Ref: 'zoneEB40FF1E',
154+
},
155+
}));
156+
});

0 commit comments

Comments
 (0)