Skip to content

Commit

Permalink
fix(route53-targets): ApiGateway does not accept RestApiBase (#16610)
Browse files Browse the repository at this point in the history
Closes #16227.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
kaizencc committed Sep 23, 2021
1 parent e84efd9 commit 20071bb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Expand Up @@ -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');
}
Expand Down
Expand Up @@ -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',
},
}));
});

0 comments on commit 20071bb

Please sign in to comment.