Naga
Naga

Reputation: 133

AWS Lambda python function giving json headers in the output

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

Upvotes: 1

Views: 2617

Answers (1)

Prajilesh
Prajilesh

Reputation: 691

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

Upvotes: 1

Related Questions