Closed
Description
Expected Behaviour
The error happens both with 3.0.0 than with 2.43.1
Current Behaviour
The base sample from the handler docs for Api HTTP Gateway returns the following 500 error.
[ERROR] KeyError: 'http'
Traceback (most recent call last):
File "/var/task/app.py", line 26, in lambda_handler
return app.resolve(event, context)
File "/var/task/aws_lambda_powertools/event_handler/api_gateway.py", line 2100, in resolve
response = self._resolve().build(self.current_event, self._cors)
File "/var/task/aws_lambda_powertools/event_handler/api_gateway.py", line 2194, in _resolve
method = self.current_event.http_method.upper()
File "/var/task/aws_lambda_powertools/utilities/data_classes/api_gateway_proxy_event.py", line 317, in http_method
return self.request_context.http.method
File "/var/task/aws_lambda_powertools/utilities/data_classes/common.py", line 467, in method
return self["requestContext"]["http"]["method"]
Code snippet
from requests import Response
from aws_lambda_powertools import Logger, Tracer
from aws_lambda_powertools.event_handler import APIGatewayHttpResolver
from aws_lambda_powertools.logging import correlation_paths
from aws_lambda_powertools.utilities.typing import LambdaContext
tracer = Tracer()
logger = Logger()
app = APIGatewayHttpResolver()
@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]}
# You can continue to use other utilities just as before
@logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_HTTP)
@tracer.capture_lambda_handler
def lambda_handler(event: dict, context: LambdaContext) -> dict:
return app.resolve(event, context)
Possible Solution
No response
Steps to Reproduce
Deploy the lambda and executed the /todos request using an HTTP gateway.
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.8
Packaging format used
PyPi
Debugging logs
No response
Metadata
Metadata
Assignees
Type
Projects
Status
Closed