-
Notifications
You must be signed in to change notification settings - Fork 421
Docs: HTTP options not supported in decorator #1922
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
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Thank you @TownCube for flagging it - we'll get it fixed tomorrow. Out of curiosity, how do you plan on handling pre-flight requests? Maybe the CORSConfig[1] feature can help? If CORSConfig isn't sufficient, you can use app.route("*", method="OPTIONS") in the meantime. Thank you for helping us improve everyone's experience. [1] CORSConfig handles both pre-flight and auto-injecting CORS headers for responses/errors. Code snippet below from the docs import requests
from requests import Response
from aws_lambda_powertools import Logger, Tracer
from aws_lambda_powertools.event_handler import APIGatewayRestResolver, CORSConfig
from aws_lambda_powertools.logging import correlation_paths
from aws_lambda_powertools.utilities.typing import LambdaContext
tracer = Tracer()
logger = Logger()
cors_config = CORSConfig(allow_origin="https://example.com", max_age=300)
app = APIGatewayRestResolver(cors=cors_config)
@app.get("/todos")
@tracer.capture_method
def get_todos():
todos: Response = requests.get("https://jsonplaceholder.typicode.com/todos")
todos.raise_for_status()
# for brevity, we'll limit to the first 10 only
return {"todos": todos.json()[:10]}
@app.get("/todos/<todo_id>")
@tracer.capture_method
def get_todo_by_id(todo_id: str): # value come as str
todos: Response = requests.get(f"https://jsonplaceholder.typicode.com/todos/{todo_id}")
todos.raise_for_status()
return {"todos": todos.json()}
@app.get("/healthcheck", cors=False) # optionally removes CORS for a given route
@tracer.capture_method
def am_i_alive():
return {"am_i_alive": "yes"}
# You can continue to use other utilities just as before
@logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_REST)
@tracer.capture_lambda_handler
def lambda_handler(event: dict, context: LambdaContext) -> dict:
return app.resolve(event, context) |
Hi @TownCube! I assigned this problem to myself, but I need to understand this in detail, mainly because we can help others to explain how to use As @heitorlessa mentioned, I'm also curious about what scenarios might be useful for these options and how can we handle pre-flight requests. Of course, we can add the Thank you |
My use case is for dynamic CORS for both internal and external pages (so two CORS URLs) that consume the same API, hopefully I'll no longer need this once #1006 is resolved. |
Hi @TownCube! What do you think about collaborating on this new feature submitting a PR, or even reviewing the code once we have the PR ready? Thank you so much. |
|
This is now released under 2.9.0 version! |
What were you searching in the docs?
HTTP Methods states:
You can use named decorators to specify the HTTP method that should be handled in your functions. That is, app.<http_method>, where the HTTP method could be get, post, put, patch, delete, and options.
However when you try and use app.options you get:
AttributeError: 'APIGatewayRestResolver' object has no attribue 'options'
Is this related to an existing documentation section?
https://awslabs.github.io/aws-lambda-powertools-python/2.8.0/core/event_handler/api_gateway/#http-methods
How can we improve?
Amend the documentation to make it clear not all HTTP methods are supported.
Got a suggestion in mind?
No response
Acknowledgment
The text was updated successfully, but these errors were encountered: