getting [ERROR] KeyError: 'http' #5163
Replies: 1 comment 2 replies
-
Hi @lalitbyteiq! Thanks for opening this discussion. I'm quite confused about the scenario here and please help me understand it better. If I understand correctly, when you are using the above code, things are working as expected with Amazon API Gateway HTTP, right? But you mentioned that when using RestAPI (in Amazon API Gateway?) it crashes. Is that correct? If yes, it's because AWS send different payloads to Lambda when integrating Lambda with Rest/HTTP API. If you want to integrate RestAPI with Lambda and use Powertools, please use APIGatewayRestResolver resolver. Please let me know if you need additional help. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
im getting bellow exception with rest api
but whilke using http api in api gateway its working
sample code :
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
from pydantic import BaseModel, Field
tracer = Tracer()
logger = Logger()
app = APIGatewayHttpResolver()
class InputRequest(BaseModel):
userId: int
title: str
completed: bool = None
@app.get("/ping")
@tracer.capture_method
def get_ping():
@app.get("/todo/{task}")
@tracer.capture_method
def get_todos(task: str):
return {"todos": f"todo has been included {task}", "status": "200"}
@app.post("/post-test/")
@tracer.capture_method
def get_todos(input: InputRequest):
return input.model_dump()
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:
print(event)
return app.resolve(event, context)
Beta Was this translation helpful? Give feedback.
All reactions