title: How to POST login information to API Gateway to GET object from Amazon S3
body: <p>I'm trying to get authentication with Cognito working for an Amazon S3 static website.</p>
  <p>I've made a login page in a separate bucket that has a form for entering the username/password. Once this is submitted, it authenticates using Cognito and, if successful, sends a POST request to API Gateway with the resulting token in the authorization header.</p>
  <p>Here's the relevant code:</p>
  <pre><code>$(function onDocReady() {
      $('#signinForm').submit(handleSignin);
  });
  
  function handleSignin(event) {
      var username = $('#usernameInputSignin').val();
      var password = $('#passwordInputSignin').val();
      event.preventDefault();
      signin(username, password,
          function signinSuccess(result) {
              console.log('Successfully Logged In');
              token = result.getAccessToken().getJwtToken();
              alert('access token: ' + token);
              sendToken(token);
          },
          function signinError(err) {
              alert(err);
          }
      );
  }
  
  function sendToken(token) {
      $.ajax({
          type: 'POST',
          url: _config.api.invokeUrl,
          headers: {
              Authorization: token
          },
          success: function(res){
              alert('It worked!');
          },
          error: function () {
              alert('Error stack: ' + (new Error()).stack);
          }
       });
  }
  </code></pre>
  <p>My API Gateway is set up as an S3 proxy, so the resources are the bucket and file name for my S3 webpage. The bucketname/filename resource accepts the POST request and is configured with a Cognito authorizer to check the token. The POST method is associated with an integration request that should send a GET request to S3 to grab the webpage.</p>
  <p>However, when I test this out, I keep getting a <code>405 Method Not Allowed</code> for the POST request. I thought this was a CORS problem at first, but I've configured API Gateway to work with that so I don't think that's the problem.</p>
  <p>Here's what is displayed in the network console (I edited out some things to try to shorten it):</p>
  <pre><code>General:
  Request URL: [login-page-URL]
  Request Method: POST
  Status Code: 405 Method Not Allowed
  
  Response Headers:
  Allow: GET, HEAD, OPTIONS
  Content-Length: 422
  Content-Type: text/html; charset=utf-8
  Date: Fri, 25 May 2018 17:29:31 GMT
  Server: AmazonS3
  
  Request Headers:
  Accept: */*
  Accept-Encoding: gzip, deflate
  Accept-Language: en-US,en;q=0.9
  Authorization: [my-token]
  Connection: keep-alive
  Content-Length: 0
  Host: [login-page-URL]
  Origin: [login-page-URL]
  Referer: [login-page-URL]
  User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36
  X-Requested-With: XMLHttpRequest
  </code></pre>
  <p>So to me, it looks like the source of the request for my S3 webpage comes from my login page. Shouldn't it be coming from the API Gateway?</p>
  <p>And why does a POST to the API Gateway lead to a POST request for the S3 webpage? How can I make a POST to my API Gateway lead to a GET from S3 to get my static webpage? If I set up the integration request for my POST request to send a GET request to my S3 webpage, shouldn't that work?</p>
  <p>I'm very unfamiliar with JavaScript and API Gateway, so I'm not sure if it's a problem with my code, or the API Gateway configuration, or both. I appreciate the help!</p>
  <p>EDIT: Here's a screenshot of what I've got configured on API Gateway:
  <a href="https://i.stack.imgur.com/AZ8AD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AZ8AD.png" alt="API Gateway configuration" /></a></p>
  <p>I also have GET methods in there for the resources, to test that the API Gateway was working (and those worked fine).</p>