-
Notifications
You must be signed in to change notification settings - Fork 403
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
Docs: Syntax for routing rules doesn't seem to be documented anywhere #2962
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hello @johnmreynolds! Thanks for bringing up this important point about the documentation. If it was difficult for you to find clear information in our documentation, it may be difficult for others too and we need to fix it. Let me split this issue to make it easier to define the next steps. 1 - Method signature:
In some special cases, developers can add a regex to catch all routes, or create more advanced dynamic routes
I think the confusion here is that even the signature method is a string, behind the hood we compile a regex to make it more flexible. In this method we have some regex examples, but I agree that is hard to find. 2 - Subfolders:
Can you please elaborate a little more on that? I didn't understand the point of subfolders. We support a path like 3 - Next steps: I'm adding the "Pending customer" status because we want to hear from you before proceeding. Thanks |
Thanks. On the topic of subfolders, github mangled my comment which included angle brackets, so my example made no sense. What I meant is like in your example: where customer_id captures the path, it seems not to work if what would be captured for customer_id contains a slash, so is a subfolder of /powertools/. This is probably sensible, and I think is covered by the examples in the source you pointed at (implied by the word boundary match) but I was just noting I couldn't find this documented anywhere. On how to improve the documentation, I think yes it could do with small additions of:
|
Hello @johnmreynolds! Thanks for adding your ideas to improve the documentation.
Except the regex case, where we don't have a detailed section, the other things like dynamic and static path we already have in our documentation. However, I think that since this is split into multiple sections of our documentation, it might be good to create a new section called "Working with Rules" or something similar to make it clearer and explain these gaps.
It can be covered in this new section.
Same for the previous question. Do you want to send a PR so we can work together? It would be great to have your contribution to improve the documentation of a widely used utility in Powertools. This PR can be a draft, in case you don't have all the information and I'll help you with whatever you need. Thanks |
Adding backlog status until we start working on it. |
I want to share my experience (originally from discussion #2976 ): In the documentation, it is stated in the section about catch-all routes the following:
I understood this to mean that in the case where a more specific match is found, that it will pick the more explicit match over the other. For instance: @app.get(".+")
def catch_all():
pass
@app.get("/my/resource/<resource_id>")
def more_explicit():
pass In this case, I would think from the docs that a request to /my/resource/12345 would invoke more_explicit, but in practice I see the opposite happen (catch_all is invoked for everything). In fact, it does this no matter what order the methods are added in. This seems like a bug honestly. But, I can see the difficulty in determining which rules are more explicit than others. How exactly does one determine that reliably from a regex? I suggest adding the ability to explicitly define the priority of a rule against others. Something like: @app.get(".+", priority=2)
def catch_all():
pass
@app.get("/my/resource/<resource_id>", priority=1)
def more_explicit():
pass Perhaps with the following behavior:
Basically, let the user determine which is more important than the other instead of trying to infer it. This way, at least the user has a way out if there is a bug in the ordering |
Hello everyone! Thank you for all your contributions and discoveries. I'm adding this issue in the current iteration (26th Aug to 8th Sept) to work on 1) improving the documentation, 2) seeing if we have any bugs we need to fix, and 3) checking if we can improve the developer experience in any way. I will keep you posted on updates. |
@app.get("/job/<name>/builds")
def get_job_builds(name):
pass I was not able to make this type of rule work. I kept getting 404 back indicating it wasn't matching.
In general, Powertools provides a lot of "magic" which is great, except I had to keep going to the source code to figure out how everything worked. In the end I found the cognitive overhead too much and replaced it with my own router which better matched my simpler use case. Thank you for this excellent tool and I'll revisit using it once I have enough code to justify needing all the power it provides. |
hey @jaysoffian, appreciate you taking the time to share what's been challenging -- while I couldn't reproduce the 404 issue (picture) and you are working on a custom router, please allow me to provide additional context for whoever is reading next.
As long as your API Gateway is configured with the correct routing to Lambda, it is a HTTP GET request, there's no reason for that function not to be called. Despite the incorrect return ( For troubleshooting, we have a debug mode that prints out more details about the routing logic, doesn't sanitize exceptions, and whatnot that you might need in Dev mode: https://docs.powertools.aws.dev/lambda/python/latest/core/event_handler/api_gateway/#debug-mode
That's right. We'd be more than happy to add a
That's on us. The original data is available under In today's release for Middleware support, I've added an example to cover that. Still, we can add a note under this section.
Appreciate your feedback. The reason we did it like that is for non-developers to get a sense of what's before and after. We've had feedback from customers before that they couldn't understand the need for Powertools, and this was a response to that. As for your feedback, one area we'd like to invest is in more specific tutorials. That way, we can cover a broader range of areas and yet meet the diverse persona that use Powertools for AWS today. If you've got ideas for Tutorials, please don't hesitate in creating a documentation issue. If you'd like to contribute, we're also more than happy to mentor tech writing too! To close, we're listening and always have! The minute we stop it's when we lose our identity and tenets on working backwards from the community. We're more than happy to jump on a call with anyone to troubleshoot when needed (bandwidth permits) - please join us on Discord with 502 other people too 🙏🏻 |
What were you searching in the docs?
I've been trying to find any documentation on how the routing rules work, but even in the API reference it's just documented as being a 'str'.
https://docs.powertools.aws.dev/lambda/python/latest/api/event_handler/index.html#aws_lambda_powertools.event_handler.ApiGatewayResolver.route
From the tutorials and source code, it looks like this should be a regex, but there is no indication of what regex syntax this follows, or how variable capture works with decorated functions.
For example, the tutorials include things like @app.get("/subscriptions/") which seems to be a curious syntax, and I can't find any documentation on this. Also, it doesn't seem to work for subfolders which is weird.
Is this related to an existing documentation section?
https://docs.powertools.aws.dev/lambda/python/latest/api/event_handler/index.html#aws_lambda_powertools.event_handler.ApiGatewayResolver.route
How can we improve?
Document how the routing rules work somewhere.
Got a suggestion in mind?
No response
Acknowledgment
The text was updated successfully, but these errors were encountered: