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

Bug: Base HTTP gateway resolver sample fails #5321

Closed
andreacfm opened this issue Oct 6, 2024 · 4 comments
Closed

Bug: Base HTTP gateway resolver sample fails #5321

andreacfm opened this issue Oct 6, 2024 · 4 comments
Assignees

Comments

@andreacfm
Copy link

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

@andreacfm andreacfm added bug Something isn't working triage Pending triage from maintainers labels Oct 6, 2024
Copy link

boring-cyborg bot commented Oct 6, 2024

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@leandrodamascena
Copy link
Contributor

leandrodamascena commented Oct 6, 2024

Ciao @andreacfm, thanks for opening this issue! I couldn't reproduce the error and I'm wondering if you are using Payload v1.0 in this integration. You should use Payload v2.0 to use this Resolver. Payload v1.0 is supported in APIGatewayRestResolver, but I recommend you to use Payload v2.0 in HTTP API.

I would also like to ask if you are using Terraform to deploy this workload, because this is a known issue that Terraform defaults to Payload v1.0 if the version is not provided.

Image

Please let me know if changing the version fixed the problem and if I can help with anything else.

@leandrodamascena leandrodamascena self-assigned this Oct 6, 2024
@leandrodamascena leandrodamascena added not-a-bug and removed bug Something isn't working triage Pending triage from maintainers labels Oct 6, 2024
@leandrodamascena leandrodamascena moved this from Triage to Pending customer in Powertools for AWS Lambda (Python) Oct 6, 2024
@andreacfm
Copy link
Author

@leandrodamascena my bad. I was using 1.0 payloads. Thanks for checking in.

@github-project-automation github-project-automation bot moved this from Pending customer to Coming soon in Powertools for AWS Lambda (Python) Oct 7, 2024
Copy link
Contributor

github-actions bot commented Oct 7, 2024

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

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

No branches or pull requests

2 participants