File tree 2 files changed +26
-3
lines changed
packages/@aws-cdk/aws-apigateway
2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -322,8 +322,11 @@ export abstract class RestApiBase extends Resource implements IRestApi {
322
322
protected cloudWatchAccount ?: CfnAccount ;
323
323
324
324
constructor ( scope : Construct , id : string , props : RestApiBaseProps = { } ) {
325
- super ( scope , id ) ;
326
- this . restApiName = props . restApiName ?? id ;
325
+ const restApiName = props . restApiName ?? id ;
326
+ super ( scope , id , {
327
+ physicalName : restApiName ,
328
+ } ) ;
329
+ this . restApiName = restApiName ;
327
330
328
331
Object . defineProperty ( this , RESTAPI_SYMBOL , { value : true } ) ;
329
332
}
@@ -736,7 +739,7 @@ export class RestApi extends RestApiBase {
736
739
super ( scope , id , props ) ;
737
740
738
741
const resource = new CfnRestApi ( this , 'Resource' , {
739
- name : this . restApiName ,
742
+ name : this . physicalName ,
740
743
description : props . description ,
741
744
policy : props . policy ,
742
745
failOnWarnings : props . failOnWarnings ,
Original file line number Diff line number Diff line change @@ -242,4 +242,24 @@ describe('lambda api', () => {
242
242
] ,
243
243
} ) ;
244
244
} ) ;
245
+
246
+ test ( 'LambdaRestApi allows passing GENERATE_IF_NEEDED as the physical name' , ( ) => {
247
+ // GIVEN
248
+ const stack = new cdk . Stack ( ) ;
249
+
250
+ // WHEN
251
+ new apigw . LambdaRestApi ( stack , 'lambda-rest-api' , {
252
+ handler : new lambda . Function ( stack , 'handler' , {
253
+ handler : 'index.handler' ,
254
+ code : lambda . Code . fromInline ( 'boom' ) ,
255
+ runtime : lambda . Runtime . NODEJS_10_X ,
256
+ } ) ,
257
+ restApiName : cdk . PhysicalName . GENERATE_IF_NEEDED ,
258
+ } ) ;
259
+
260
+ // THEN
261
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGateway::RestApi' , {
262
+ Name : Match . absent ( ) ,
263
+ } ) ;
264
+ } ) ;
245
265
} ) ;
You can’t perform that action at this time.
0 commit comments