Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(apigatewayv2): support for setting routeSelectionExpression for an HTTP API #31373

Merged
merged 13 commits into from
Sep 13, 2024

Conversation

badmintoncryer
Copy link
Contributor

@badmintoncryer badmintoncryer commented Sep 9, 2024

Issue # (if applicable)

Closes #31104.

Reason for this change

Cloudformation supports for configuring routeSelectionExpression but AWS CDK doesn't support this.

Description of changes

Added routeSelectionExpression prop to HttpApiProps.

For HTTP API, routeSelectionExpression must be ${request.method} ${request.path}. Therefore, I defined routeSelectionExpression as boolean and set it to ${request.method} ${request.path}.

Description of how you validated changes

Added unit and integ tests.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team September 9, 2024 12:39
@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 distinguished-contributor [Pilot] contributed 50+ PRs to the CDK labels Sep 9, 2024
@badmintoncryer badmintoncryer changed the title feat(apigatewayv2): support for setting routeSelectionExpression feat(apigatewayv2): support for setting routeSelectionExpression for an HTTP API Sep 9, 2024
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@aws-cdk-automation aws-cdk-automation dismissed their stale review September 10, 2024 04:00

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@badmintoncryer badmintoncryer marked this pull request as ready for review September 10, 2024 13:10
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Sep 10, 2024
Copy link
Contributor

@go-to-k go-to-k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR! I left some minor comments.

packages/aws-cdk-lib/aws-apigatewayv2/lib/http/api.ts Outdated Show resolved Hide resolved
@@ -434,6 +443,7 @@ export class HttpApi extends HttpApiBase {
corsConfiguration,
description: props?.description,
disableExecuteApiEndpoint: this.disableExecuteApiEndpoint,
routeSelectionExpression: props?.routeSelectionExpression === true ? '$request.method $request.path' : undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why $request.method $request.path and not ${request.method} ${request.path}?

It is probably correct as the deployment has not failed. However, the CFn documentation also says it in brackets, and the selection expression guide says the following.

To use multiple variables in a selection expression, enclose the variable in brackets. For example, ${request.path.name} ${request.path.id}.

https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-parameter-mapping.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my mistakes! Thank you for your confirmation!!

Comment on lines 96 to 97
The `routeSelectionExpression` option can be configured.
In the HTTP API, only the value `$request.method $request.path` is allowed, and it can be configured by enabling `routeSelectionExpression`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a bit of redundancy in the first and second halves, could you simplify it a bit?

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Sep 12, 2024
@@ -234,6 +234,19 @@ describe('HttpApi', () => {
});
});

test('routeSelectionExpression is enabled', () => {
Copy link
Contributor

@go-to-k go-to-k Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, it might be good to write a test for RouteSelectionExpression: Match.absent() when routeSelectionExpression is undefined (or false too?), as a test for the ternary operator, just in case.

@badmintoncryer
Copy link
Contributor Author

@go-to-k Thank you for your review! I've addressed your comments.

@go-to-k
Copy link
Contributor

go-to-k commented Sep 13, 2024

@badmintoncryer Could you update snapshots?

@badmintoncryer
Copy link
Contributor Author

badmintoncryer commented Sep 13, 2024

@go-to-k Thanks to your notification. I've updated a snapshot.

Copy link
Contributor

@go-to-k go-to-k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Sep 13, 2024
Copy link
Contributor

mergify bot commented Sep 13, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Sep 13, 2024
Copy link
Contributor

mergify bot commented Sep 13, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 16684fd
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 36baf51 into aws:main Sep 13, 2024
9 checks passed
Copy link
Contributor

mergify bot commented Sep 13, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 13, 2024
@badmintoncryer badmintoncryer deleted the 31104-routeSelectionExpression branch September 13, 2024 23:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
distinguished-contributor [Pilot] contributed 50+ PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
4 participants