Event is empty in my lambda function when using Rest API

0

So I have a lambda function that's the following: def lambda_handler(event, context): http = urllib3.PoolManager() return { "statusCode": 200, "headers": { "Content-Type": "application/json" }, "body": "{"message": "Hello from Lambda!"}", "test": event }

If I test run the event with some event JSON, it returns what I want. But... when I test to run the lambda through my rest API I created I either get the error 502 when "Use Lambda Proxy integration" is enabled. Or when it's disabled event is always empty. I have tried to setup a link the following way:

https://something.execute-api.eu-north-1.amazonaws.com/test/test/{id}

Where you enter an {id} for example and I can catch it in the event. But how can I fix so event is an actual thing and actually getting any information? If you feel like im missing some information that might be important just ask, I don't know what could be useful.

1 Antwort
0

If you're using a non-proxy Lambda integration, you need to craft your payload using a model in the method request in API Gateway. You can see an example of how this works here [1]. If you're using a Lambda proxy integration type and you're getting a 502 error, this would often be a result of your function response being malformed and therefore API Gateway is unable to parse it. The response for a Lambda proxy integration must conform to the format that API Gateway is expecting in order for it to be successfully parsed. You can see the required format here [2]. If you're still having issues I'd recommend setting up execution logs for your API so that you can get more information on the cause of the failure.

Resources:

[1] Tutorial: Build an API Gateway REST API with Lambda non-proxy integration - Create an API with Lambda non-proxy integration - https://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started-lambda-non-proxy-integration.html#getting-started-new-api [2] Set up Lambda proxy integrations in API Gateway - Output format of a Lambda function for proxy integration - https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-output-format

AWS
Kevin_C
beantwortet vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen