File tree 2 files changed +49
-1
lines changed
packages/@aws-cdk/aws-route53-targets
2 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ export class ApiGatewayDomain implements route53.IAliasRecordTarget {
26
26
* `ApiGatewayDomain` class.
27
27
*/
28
28
export class ApiGateway extends ApiGatewayDomain {
29
- constructor ( api : apig . RestApi ) {
29
+ constructor ( api : apig . RestApiBase ) {
30
30
if ( ! api . domainName ) {
31
31
throw new Error ( 'API does not define a default domain name' ) ;
32
32
}
Original file line number Diff line number Diff line change @@ -106,3 +106,51 @@ test('fails if an ApiGateway is used with an API that does not define a domain n
106
106
} ) ;
107
107
} ) . toThrow ( / A P I d o e s n o t d e f i n e a d e f a u l t d o m a i n n a m e / ) ;
108
108
} ) ;
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments