1

I am trying to invoke lambda service. When I hit the Get method(under Api gateway->stages->GET) invoke Url I see json headers and status code also. But in the acloud guru lecture video, I see just the body. Can anyone please tell what am I missing here.

Here is my python function:

def lambda_handler(event, context):

print("In lambda handler")

resp = {

   "statusCode": 200,

   "headers": {

   "Access-Control-Allow-Origin": "*",

},

"body": "myName"

}

return resp

Actual Output:

{"statusCode": 200, "headers": {"Access-Control-Allow-Origin": "*"}, "body": "myName"}

Expected output:

myName

1 Answer 1

1

here you have used lambda proxy integration and did not enable it in API gateway level.

You can enable it under Integration request, see the image below enter image description here

There are 2 types of API Gateway and Lambda integration

  1. Proxy Integration - Request to API gateway is directly forwarded to lambda and response is sent from lambda. we have to create the response body with appropriate status code and headers inside the lambda in this integration
  2. Lambda Integration - request can be modified before sending to lambda and response can be modified from lambda response in API gateway level using mapping templates

This blog post gives more details about the 2 integrations https://medium.com/@lakshmanLD/lambda-proxy-vs-lambda-integration-in-aws-api-gateway-3a9397af0e6d

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks!, this solved my issue. How did you know? Did you face this issue earlier?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.