title: AWS API Gateway Integration Response
body: <p>I am using AWS Lambda and API Gateway and facing an issue with my API's response code,<br>
  In case of an exception I am setting responseCode as 400 in my response,<br>
  But the API status is 200.</p>
  
  <p>I found that my solution is related to AWS API Gateway's Integration Response,<br>
  I created all the possible Http Status codes that my application needs,<br>
  And I set the Lambda Error Regex in Integration Response,<br>
  But I still get API status as 200 despite me sending "responseCode" : "400", in my APIs response(response type is JsonObject in Java).</p>
  
  <p>I have the following code AWS Lambda code,<br>
  I am passing ErrorCode as query parameter to my Get method,<br>
  And returning the same Error code in response eg. "responseCode" : "400".</p>
  
  <p><strong>My expected output is "responseCode" : "400" but, the API's status should also become 400 instead of 200.</strong></p>
  
  <pre><code>public class MainHandler implements RequestHandler&lt;JSONObject, JSONObject&gt; {
  
      public JSONObject handleRequest(JSONObject request, Context context) {
  
          try {
              JSONObject requestJson = (JSONObject) new JSONParser().parse(request.toString());
              System.out.println("RequestJson : " + requestJson);
  
              JSONObject params = (JSONObject) requestJson.get("params");
              System.out.println("Params : " + params);
  
              JSONObject queryString = (JSONObject) params.get("querystring");
              System.out.println("QueryString : " + queryString);
  
              String error = (String) queryString.get("errorCode");
              System.out.println("ErrorCode : " + error);
  
              JSONObject resp = new JSONObject();
              resp.put("responseCode", error);
  
              return resp;
          } catch (Exception e) {
              e.printStackTrace();
              return null;
          }
      }
  }
  </code></pre>
  
  <p><strong>AWS API Gateway Method Response -</strong>
  <a href="https://i.stack.imgur.com/Z9s0W.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Z9s0W.png" alt="enter image description here"></a></p>
  
  <p><strong>AWS API Gateway Integration Response -</strong>
  <a href="https://i.stack.imgur.com/jFCUF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jFCUF.png" alt="enter image description here"></a></p>
  
  <p><strong>Postman response -</strong><br>
  The API status shows 200 Ok, whereas I want it as 400.
  <a href="https://i.stack.imgur.com/oCi4B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oCi4B.png" alt="enter image description here"></a></p>
  
  <p><strong>I am referring the following links -</strong><br>
  1. <a href="https://forums.aws.amazon.com/thread.jspa?threadID=192918" rel="nofollow noreferrer">https://forums.aws.amazon.com/thread.jspa?threadID=192918</a><br>
  2. <a href="https://stackoverflow.com/questions/31329495/is-there-a-way-to-change-the-http-status-codes-returned-by-amazon-api-gateway/31371862">Is there a way to change the http status codes returned by Amazon API Gateway?</a></p>