Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS API Gateway: Execution failed due to configuration error: Invalid JSON in response

I have an API gateway setup with a Custom Authorizer that calls a Lambda function. For testing purposes I copied the example from here: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-as-simple-proxy-for-lambda.html#api-gateway-proxy-integration-lambda-function-nodejs

I get the same answer as in the documentation but when I test the authorizer I get this stacktrace:

    Endpoint request body after transformations: {"type":"TOKEN","authorizationToken":"test","methodArn":"arn:aws:execute-api:ap-southeast-2:893445519708:uyue0zqh15/null/GET/"}
    Authorizer result body before parsing: {"statusCode":200,"headers":{"x-custom-header":"my custom header value"},"body":"{\"message\":\"Hello World!\",\"input\":{\"type\":\"TOKEN\",\"authorizationToken\":\"test\",\"methodArn\":\"arn:aws:execute-api:ap-southeast-2:893445519708:uyue0zqh15/null/GET/\"}}"}
    Execution failed due to configuration error: Invalid JSON in response: {"statusCode":200,"headers":{"x-custom-header":"my custom header value"},"body":"{\"message\":\"Hello World!\",\"input\":{\"type\":\"TOKEN\",\"authorizationToken\":\"test\",\"methodArn\":\"arn:aws:execute-api:ap-southeast-2:893445519708:uyue0zqh15/null/GET/\"}}"}
    AuthorizerConfigurationException

Why doesn't the authorizer like the JSON response?

like image 418
Alex Lungu Avatar asked Jan 05 '17 13:01

Alex Lungu


People also ask

What is 4XX error in API gateway?

In this output, statusCode is typically 4XX for a client error and 5XX for a server error. API Gateway handles these errors by mapping the Lambda error to an HTTP error response, according to the specified statusCode .

How do I return custom HTTP status codes from a Lambda function in Amazon API gateway?

The easiest way to set custom HTTP status code is to setup a Lambda Proxy Integration in API Gateway. In API Gateway > Resource > Actions Dropdown > Create Method > tick Lambda Proxy Integration and select appropriate Lambda function. For async functions just return with an object with statusCode and body .


1 Answers

I just ran into the same error but in my case the problem was that context was too complex - apparently it cannot contain array or object-valued keys.

This is documented here: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html

Notice that you cannot set a JSON object or array as a valid value of any key in the context map.

(I was trying to set a decoded JWT as the context, which has an array-valued roles key. I'm now sending the encoded JWT instead)

like image 149
Rob Hogan Avatar answered Oct 09 '22 19:10

Rob Hogan