Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Error: Proxy integrations cannot be configured to transform responses

I'm a beginner in Amazon's Lambda-API implementations.

I'm just deploying a very simple API: a very simple lambda function with Python 2.7 printing "Hello World" that I trigger with API Gateway. However, when I click on the Invoke URL link, it tells me "{"message": "Internal server error"}".

Thus, I'm trying to see what is wrong here, so I click on the API itself and I can see the following being grey in my Method Execution: "Integration Response: Proxy integrations cannot be configured to transform responses."

enter image description here

I have tested many different configurations but I still face the same error. I have no idea why this step is grey.

like image 960
sammtt Avatar asked Dec 03 '17 23:12

sammtt


People also ask

What is proxy integration in AWS API gateway?

An HTTP proxy integration enables you to connect an API route to a publicly routable HTTP endpoint. With this integration type, API Gateway passes the entire request and response between the frontend and the backend. To create an HTTP proxy integration, provide the URL of a publicly routable HTTP endpoint.

How do I enable CORS on API gateway with Lambda proxy integration?

To enable CORS for the Lambda proxy integration, you must add Access-Control-Allow-Origin: domain-name to the output headers . domain-name can be * for any domain name. The output body is marshalled to the frontend as the method response payload.


2 Answers

I had the same problem when trying to integrate API gateway and lambda function. Basically, after spending a couple of hours, I figure out. So when you were creating a new resource or method the Use Lambda Proxy integration was set by default.

So you need to remove this. Follow to Integration Request and untick the Use Lambda Proxy integration enter image description here

you will see the following picture enter image description here

Then in you Resources, Atction tab, choose Enable CORS enter image description here enter image description hereenter image description here

Once this done Deploy your API once again and test function. Also, this topic will explain what's happening under the hood.

Good luck...

like image 114
hasskell Avatar answered Sep 18 '22 05:09

hasskell


The Lambda response should be in a specific format for API gateway to process. You could find details in the post. https://aws.amazon.com/premiumsupport/knowledge-center/malformed-502-api-gateway/

exports.handler = (event, context, callback) => {

var responseBody = {
    "key3": "value3",
    "key2": "value2",
    "key1": "value1"
};

var response = {
    "statusCode": 200,
    "headers": {
        "my_header": "my_value"
    },
    "body": JSON.stringify(responseBody),
    "isBase64Encoded": false
};
callback(null, response);
like image 22
aditya Avatar answered Sep 18 '22 05:09

aditya