You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importrequestsfromaws_lambda_powertoolsimportLogger, Tracerfromaws_lambda_powertools.event_handlerimportAPIGatewayRestResolver, Response, content_typesfromaws_lambda_powertools.event_handler.exceptionsimportNotFoundErrorfromaws_lambda_powertools.loggingimportcorrelation_pathsfromaws_lambda_powertools.utilities.typingimportLambdaContexttracer=Tracer()
logger=Logger()
app=APIGatewayRestResolver()
@app.not_found@tracer.capture_methoddefhandle_not_found_errors(exc: NotFoundError) ->Response:
logger.info(f"Not found route: {app.current_event.path}")
returnResponse(status_code=418, content_type=content_types.TEXT_PLAIN, body="I'm a teapot!")
@app.get("/todos")@tracer.capture_methoddefget_todos():
todos: requests.Response=requests.get("https://jsonplaceholder.typicode.com/todos")
todos.raise_for_status()
# for brevity, we'll limit to the first 10 onlyreturn {"todos": todos.json()[:10]}
# 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_handlerdeflambda_handler(event: dict, context: LambdaContext) ->dict:
returnapp.resolve(event, context)
Expected Behaviour
Importing
Response
to return fine-grained response should be possible as per documentationCurrent Behaviour
When importing
Response
from the top-levelevent_handler
it yields anImportError
Code snippet
Possible Solution
No response
Steps to Reproduce
Follow the documentation on returning fine grained responses.
AWS Lambda Powertools for Python version
latest
AWS Lambda function runtime
3.9
Packaging format used
Lambda Layers
Debugging logs
No response
The text was updated successfully, but these errors were encountered: