title: AWS API Gateway - CORS + POST not working
body: <p><strong>CORS</strong> is really driving me crazy and I'm really out of ideas as of what to try to make it work.</p>
  
  <p>I have created a simple APIG Api with 1 resource called 'abc' and added 2 methods <em>GET</em> and <em>POST</em> both with <em>Authorization</em> set to <em>NONE</em> and <em>API Key Required</em> set to <em>false</em>, everything deployed to a stage called 'dev'.</p>
  
  <p>Of course I enabled <strong>CORS</strong> on both methods and I see the 3 headers <strong>Access-Control-Allow-Origin</strong>, <strong>Access-Control-Allow-Headers</strong> and <strong>Access-Control-Allow-Methods</strong> added to the <em>OPTIONS</em> method and the <strong>Access-Control-Allow-Origin</strong> added to the <em>POST</em> and <em>GET</em> methods.</p>
  
  <p>Both calls are mapped to the same <em>lambda</em> function that simply outputs a 'Hello from Lambda' text to the console.</p>
  
  <p>Then I have created a simple html page I hosted as a <em>static website</em> on <strong>S3</strong>, pointed a domain to it using <strong>Route53</strong> and started testing the API using <strong>jQuery $.ajax</strong> to make the calls.</p>
  
  <p>All seems easy, straightforward and exactly as explained in the docs, except only the <em>GET</em> works and outputs the text to the console as expected. The <em>POST</em> version results in the following error: </p>
  
  <p><strong><code>No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://example.com' is therefore not allowed access. The response had HTTP status code 400.</code></strong></p>
  
  <p>The preflight call works and returns 200 OK and all headers are there, but the POST call returns that error and a 400 Bad Request.</p>
  
  <p>Please any help is really appreciated, I hope the AWS team is watching too...</p>
  
  <p>Thanks guys. </p>
  
  <hr>
  
  <p>EDITED - Copied from Google Chrome:</p>
  
  <p>POST Raw Request Headers:</p>
  
  <pre><code>POST /dev/urls HTTP/1.1
  Host: kykul1mshe.execute-api.us-east-1.amazonaws.com
  Connection: keep-alive
  Content-Length: 73
  Accept: application/json, text/javascript, */*; q=0.01
  Origin: http://example.com
  User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
  Content-Type: application/json
  Referer: http://example.com/dev.html
  Accept-Encoding: gzip, deflate, br
  Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
  </code></pre>
  
  <p>POST Raw Response Headers:</p>
  
  <pre><code>HTTP/1.1 400 Bad Request
  Date: Fri, 19 Aug 2016 02:14:16 GMT
  Content-Type: application/json
  Content-Length: 177
  Connection: keep-alive
  x-amzn-RequestId: a1160e45-65b2-11e6-9766-cd61e49fbcdb
  X-Cache: Error from cloudfront
  Via: 1.1 d64756b4df47ce24d6c62b5a8de97e87.cloudfront.net (CloudFront)
  X-Amz-Cf-Id: N9mf7apicKbSM_MiZjePbEgZGIFKckWJ3lZljH8iHVKFVTcIIOQuHg==
  </code></pre>
  
  <p>This returns 400 Bad Request</p>
  
  <p>OPTIONS Raw Request Headers:</p>
  
  <pre><code>Accept:*/*
  Accept-Encoding:gzip, deflate, sdch, br
  Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
  Access-Control-Request-Headers:accept, content-type
  Access-Control-Request-Method:POST
  Connection:keep-alive
  Host:kykul1mshe.execute-api.us-east-1.amazonaws.com
  Origin:http://example.com
  Referer:http://example.com/dev.html
  User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
  </code></pre>
  
  <p>OPTIONS Raw Response Headers:</p>
  
  <pre><code>Access-Control-Allow-Headers:Content-Type,X-Amz-Date,Authorization,X-Api-Key,Cache-Control,X-Requested-With
  Access-Control-Allow-Methods:POST,OPTIONS
  Access-Control-Allow-Origin:*
  Connection:keep-alive
  Content-Length:79
  Content-Type:application/json
  Date:Fri, 19 Aug 2016 02:14:16 GMT
  Via:1.1 d64756b4df47ce24d6c62b5a8de97e87.cloudfront.net (CloudFront)
  X-Amz-Cf-Id:KpGEDmIuf5RHcUnBWuA3oEMZgWHwrjy3SpLuOflRhAD8IIx5vyKGSw==
  x-amzn-RequestId:a10bae11-65b2-11e6-bcf7-63b49c24629e
  X-Cache:Miss from cloudfront
  </code></pre>
  
  <p>This returns 200 OK</p>