title: Return Custom HTTP Status Code in AWS Java Lambda?
body: <p>I am trying to make my AWS Lambda function written in Java return an error JSON model. The problem is that when the request is sent using Postman or any other HTTP client, the HTTP Status code returned by API Gateway is 200. I need the HTTP Status code to be the one that I return in JSON.</p>
  <p>I have learned from the following documentation page that for this to work, my AWS Java Lambda code needs to return a specific header and explicitly set HTTP status code in JSON. But that still results in a 200 OK status code received by HTTP Client.</p>
  <p><a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/handle-errors-in-lambda-integration.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/apigateway/latest/developerguide/handle-errors-in-lambda-integration.html</a></p>
  <p>How do I make AWS API Gateway return the HTTP status code that I manually set in the JSON response?</p>
  <p>This is not a Proxy integration, so I cannot use the APIGatewayProxyResponseEvent.</p>
  <p>My AWS Java lambda returns JSON String that looks like this.</p>
  <pre><code>{
    &quot;statusCode&quot;: 502,
    &quot;isBase64Encoded&quot;: false,
    &quot;headers&quot;: {
      &quot;X-Amzn-ErrorType&quot;: &quot;InvalidParameterException&quot;,
      &quot;content-type&quot;: &quot;application/json&quot;
    },
    &quot;body&quot;: {
      &quot;requestId&quot;: &quot;a4c946aa-3ca9-4252-ab6c-4f5fb1c6f53e&quot;,
      &quot;errorMessage&quot;: &quot;InternalServerError Manually triggered error&quot;
    }
  }
  </code></pre>
  <p>Thank you very much for your advice!</p>