diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/aws-cdk-aws-apigatewayv2.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/aws-cdk-aws-apigatewayv2.assets.json index 2a97a56ed3ab4..d4faf85d53ac2 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/aws-cdk-aws-apigatewayv2.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/aws-cdk-aws-apigatewayv2.assets.json @@ -1,7 +1,7 @@ { - "version": "35.0.0", + "version": "36.0.24", "files": { - "f753b6c52b805082d600dd33b6be3b816c0954f254acf84347e2447774db5100": { + "9f85e0964776ba83e66fcd671c3a1742f019c357f8fc867e1890e86af1fdec7b": { "source": { "path": "aws-cdk-aws-apigatewayv2.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "f753b6c52b805082d600dd33b6be3b816c0954f254acf84347e2447774db5100.json", + "objectKey": "9f85e0964776ba83e66fcd671c3a1742f019c357f8fc867e1890e86af1fdec7b.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/aws-cdk-aws-apigatewayv2.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/aws-cdk-aws-apigatewayv2.template.json index 36bd57da384f9..27b13d1802598 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/aws-cdk-aws-apigatewayv2.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/aws-cdk-aws-apigatewayv2.template.json @@ -4,7 +4,8 @@ "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Name": "HttpApi", - "ProtocolType": "HTTP" + "ProtocolType": "HTTP", + "RouteSelectionExpression": "${request.method} ${request.path}" } }, "HttpApiDefaultStage3EEB07D6": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/cdk.out index c5cb2e5de6344..4efaa16f29af9 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/cdk.out +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/cdk.out @@ -1 +1 @@ -{"version":"35.0.0"} \ No newline at end of file +{"version":"36.0.24"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/httpapiDefaultTestDeployAssert77633A40.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/httpapiDefaultTestDeployAssert77633A40.assets.json index 1b6f704767526..ac2d13efda342 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/httpapiDefaultTestDeployAssert77633A40.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/httpapiDefaultTestDeployAssert77633A40.assets.json @@ -1,5 +1,5 @@ { - "version": "35.0.0", + "version": "36.0.24", "files": { "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { "source": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/integ.json index 1b3ad22cef14a..80fc2143882d2 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/integ.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/integ.json @@ -1,5 +1,5 @@ { - "version": "35.0.0", + "version": "36.0.24", "testCases": { "http-api/DefaultTest": { "stacks": [ diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/manifest.json index 91e40a0cbe7bb..27baec36eb925 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/manifest.json @@ -1,5 +1,5 @@ { - "version": "35.0.0", + "version": "36.0.24", "artifacts": { "aws-cdk-aws-apigatewayv2.assets": { "type": "cdk:asset-manifest", @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/f753b6c52b805082d600dd33b6be3b816c0954f254acf84347e2447774db5100.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/9f85e0964776ba83e66fcd671c3a1742f019c357f8fc867e1890e86af1fdec7b.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/tree.json index d17481862eddf..68ac7cffc7318 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.js.snapshot/tree.json @@ -19,7 +19,8 @@ "aws:cdk:cloudformation:type": "AWS::ApiGatewayV2::Api", "aws:cdk:cloudformation:props": { "name": "HttpApi", - "protocolType": "HTTP" + "protocolType": "HTTP", + "routeSelectionExpression": "${request.method} ${request.path}" } }, "constructInfo": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.ts index dac08621b9906..e60b20380a4ac 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/http/integ.api.ts @@ -6,7 +6,9 @@ import * as apigw from 'aws-cdk-lib/aws-apigatewayv2'; const app = new cdk.App(); const stack = new cdk.Stack(app, 'aws-cdk-aws-apigatewayv2'); -new apigw.HttpApi(stack, 'HttpApi'); +new apigw.HttpApi(stack, 'HttpApi', { + routeSelectionExpression: true, +}); new IntegTest(app, 'http-api', { testCases: [stack], diff --git a/packages/aws-cdk-lib/aws-apigatewayv2/README.md b/packages/aws-cdk-lib/aws-apigatewayv2/README.md index 8b74889d941cb..fdde2f476c216 100644 --- a/packages/aws-cdk-lib/aws-apigatewayv2/README.md +++ b/packages/aws-cdk-lib/aws-apigatewayv2/README.md @@ -93,6 +93,14 @@ new apigwv2.HttpApi(this, 'HttpProxyApi', { }); ``` +The `routeSelectionExpression` option allows configuring the HTTP API to accept only `${request.method} ${request.path}`. Setting it to `true` automatically applies this value. + +```ts +new apigwv2.HttpApi(this, 'HttpProxyApi', { + routeSelectionExpression: true, +}); +``` + ### Cross Origin Resource Sharing (CORS) [Cross-origin resource sharing (CORS)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) is a browser security diff --git a/packages/aws-cdk-lib/aws-apigatewayv2/lib/http/api.ts b/packages/aws-cdk-lib/aws-apigatewayv2/lib/http/api.ts index 55ff0955df3b8..53437c47a5db3 100644 --- a/packages/aws-cdk-lib/aws-apigatewayv2/lib/http/api.ts +++ b/packages/aws-cdk-lib/aws-apigatewayv2/lib/http/api.ts @@ -160,6 +160,15 @@ export interface HttpApiProps { * @default - no default authorization scopes */ readonly defaultAuthorizationScopes?: string[]; + + /** + * Whether to set the default route selection expression for the API. + * + * When enabled, "${request.method} ${request.path}" is set as the default route selection expression. + * + * @default false + */ + readonly routeSelectionExpression?: boolean; } /** @@ -434,6 +443,7 @@ export class HttpApi extends HttpApiBase { corsConfiguration, description: props?.description, disableExecuteApiEndpoint: this.disableExecuteApiEndpoint, + routeSelectionExpression: props?.routeSelectionExpression ? '${request.method} ${request.path}' : undefined, }; const resource = new CfnApi(this, 'Resource', apiProps); diff --git a/packages/aws-cdk-lib/aws-apigatewayv2/test/http/api.test.ts b/packages/aws-cdk-lib/aws-apigatewayv2/test/http/api.test.ts index e703dbd9d7d56..295986b4bc2bc 100644 --- a/packages/aws-cdk-lib/aws-apigatewayv2/test/http/api.test.ts +++ b/packages/aws-cdk-lib/aws-apigatewayv2/test/http/api.test.ts @@ -234,6 +234,32 @@ describe('HttpApi', () => { }); }); + test('routeSelectionExpression is enabled', () => { + const stack = new Stack(); + new HttpApi(stack, 'api', { + routeSelectionExpression: true, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::ApiGatewayV2::Api', { + Name: 'api', + ProtocolType: 'HTTP', + RouteSelectionExpression: '${request.method} ${request.path}', + }); + }); + + test.each([false, undefined])('routeSelectionExpression is not enabled', (routeSelectionExpression) => { + const stack = new Stack(); + new HttpApi(stack, 'api', { + routeSelectionExpression, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::ApiGatewayV2::Api', { + Name: 'api', + ProtocolType: 'HTTP', + RouteSelectionExpression: Match.absent(), + }); + }); + test('can add a vpc links', () => { // GIVEN const stack = new Stack();