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

Apigw ng new path style #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

lizard-boy
Copy link

Motivation

In LocalStack API Gateway, we currently have a specific path-style format to call execute-api: http(s)://<your-domain>:<port>/restapis/<api_id>/<stage>/_user_request_/<your-path>.
The actual AWS format is this, with the host: http(s)://<api-id>.execute-api.<domain>/<stage>/<your-path>

There are multiple problems with our current "path style" format:

  • it has restapis in the name but is shared with HTTP and WebSockets API in APIGW v2
  • for HTTP APIs, can be optional. That format does not work with that case
  • there is the custom user_request between and , which looks weird and necessitate to re-organize the parts for the user

This PR introduces a new path format for API Gateway, available with the "Next Gen" provider:
http(s)://<your-domain>:<port>/_aws/apigateway/execute-api/<api-id>/<stage>/<your-path>

This new format follows the same order as AWS, is clearer about the LocalStack-only part, is on the _aws namespace, and has execute-api in the name, which maps to the URL people are used to see.

It also sets up a deprecation path for the previous "path style" and log a message when people uses it with the new provider. We will also need to update the documentation accordingly.

Deprecation message:

2024-08-14T03:10:10.517 WARNING --- [PoolThread-twisted.internet.reactor-0] localstack.deprecations    : /restapis/<api_id>/<stage>/_user_request_ is deprecated (since 3.7.0) and will be removed in upcoming releases of LocalStack! Use /_aws/apigateway/execute-api/<api_id>/<stage> instead.

Changes

  • register new routes for the APIGW NG router
  • update the CORS handler to recognize this new router
  • add deprecation on the _user_request_ endpoint when using the NG provder
  • update the tests to use this new endpoint too

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR introduces a new path format for API Gateway in LocalStack, aligning more closely with AWS's actual format while maintaining backward compatibility.

  • Added new route '/_aws/apigateway/execute-api///' in localstack-core/localstack/services/apigateway/next_gen/execute_api/router.py
  • Implemented deprecation warning for old 'user_request' endpoint in the same file
  • Updated CORS handling in localstack-core/localstack/aws/handlers/cors.py to support the new path format
  • Modified localstack-core/localstack/services/apigateway/helpers.py to generate URLs using the new format
  • Updated tests in tests/aws/services/apigateway/test_apigateway_basic.py and tests/unit/services/apigateway/test_handler_request.py to include new path style

7 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings

Comment on lines +82 to +86
raw_uri = re.sub(
f"^/_aws/apigateway/execute-api/{context.api_id}",
"",
raw_uri,
flags=re.IGNORECASE,
Copy link

Choose a reason for hiding this comment

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

style: Consider using a constant for the path prefix '/_aws/apigateway/execute-api' to improve maintainability

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants