Skip to content

Commit

Permalink
fix(apigateway): allow using GENERATE_IF_NEEDED for the physical name…
Browse files Browse the repository at this point in the history
… in LambdaRestApi (#19638)

Fixes #9374

----

### All Submissions:

* [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
skinny85 committed Mar 31, 2022
1 parent a74d82e commit e817381
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/@aws-cdk/aws-apigateway/lib/restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,11 @@ export abstract class RestApiBase extends Resource implements IRestApi {
protected cloudWatchAccount?: CfnAccount;

constructor(scope: Construct, id: string, props: RestApiBaseProps = { }) {
super(scope, id);
this.restApiName = props.restApiName ?? id;
const restApiName = props.restApiName ?? id;
super(scope, id, {
physicalName: restApiName,
});
this.restApiName = restApiName;

Object.defineProperty(this, RESTAPI_SYMBOL, { value: true });
}
Expand Down Expand Up @@ -736,7 +739,7 @@ export class RestApi extends RestApiBase {
super(scope, id, props);

const resource = new CfnRestApi(this, 'Resource', {
name: this.restApiName,
name: this.physicalName,
description: props.description,
policy: props.policy,
failOnWarnings: props.failOnWarnings,
Expand Down
20 changes: 20 additions & 0 deletions packages/@aws-cdk/aws-apigateway/test/lambda-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,24 @@ describe('lambda api', () => {
],
});
});

test('LambdaRestApi allows passing GENERATE_IF_NEEDED as the physical name', () => {
// GIVEN
const stack = new cdk.Stack();

// WHEN
new apigw.LambdaRestApi(stack, 'lambda-rest-api', {
handler: new lambda.Function(stack, 'handler', {
handler: 'index.handler',
code: lambda.Code.fromInline('boom'),
runtime: lambda.Runtime.NODEJS_10_X,
}),
restApiName: cdk.PhysicalName.GENERATE_IF_NEEDED,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RestApi', {
Name: Match.absent(),
});
});
});

0 comments on commit e817381

Please sign in to comment.