Skip to content

Commit f7732a1

Browse files
authored
fix(apigateway): arnForExecuteApi fails on tokenized path (#20323)
Fixes #20252. ---- ### 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 `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn 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*
1 parent 10df757 commit f7732a1

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

packages/@aws-cdk/aws-apigateway/lib/restapi.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
22
import { IVpcEndpoint } from '@aws-cdk/aws-ec2';
33
import * as iam from '@aws-cdk/aws-iam';
4-
import { ArnFormat, CfnOutput, IResource as IResourceBase, Resource, Stack } from '@aws-cdk/core';
4+
import { ArnFormat, CfnOutput, IResource as IResourceBase, Resource, Stack, Token } from '@aws-cdk/core';
55
import { Construct } from 'constructs';
66
import { ApiDefinition } from './api-definition';
77
import { ApiKey, ApiKeyOptions, IApiKey } from './api-key';
@@ -368,7 +368,7 @@ export abstract class RestApiBase extends Resource implements IRestApi {
368368
}
369369

370370
public arnForExecuteApi(method: string = '*', path: string = '/*', stage: string = '*') {
371-
if (!path.startsWith('/')) {
371+
if (!Token.isUnresolved(path) && !path.startsWith('/')) {
372372
throw new Error(`"path" must begin with a "/": '${path}'`);
373373
}
374374

packages/@aws-cdk/aws-apigateway/test/restapi.test.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Template } from '@aws-cdk/assertions';
22
import { GatewayVpcEndpoint } from '@aws-cdk/aws-ec2';
33
import { testDeprecated } from '@aws-cdk/cdk-build-tools';
4-
import { App, CfnElement, CfnResource, Stack } from '@aws-cdk/core';
4+
import { App, CfnElement, CfnResource, Lazy, Stack } from '@aws-cdk/core';
55
import * as apigw from '../lib';
66

77
describe('restapi', () => {
@@ -424,6 +424,16 @@ describe('restapi', () => {
424424
expect(() => api.arnForExecuteApi('method', 'hey-path', 'stage')).toThrow(/"path" must begin with a "\/": 'hey-path'/);
425425
});
426426

427+
test('"executeApiArn" path can be a token', () => {
428+
// GIVEN
429+
const stack = new Stack();
430+
const api = new apigw.RestApi(stack, 'api');
431+
api.root.addMethod('GET');
432+
433+
// THEN
434+
expect(() => api.arnForExecuteApi('method', Lazy.string(({ produce: () => 'path' })), 'stage')).not.toThrow();
435+
});
436+
427437
test('"executeApiArn" will convert ANY to "*"', () => {
428438
// GIVEN
429439
const stack = new Stack();

0 commit comments

Comments
 (0)