title: AWS Lambda + Gateway API + React JS
body: <p>I am trying to post to my dynamoDB using react however I am getting the following error:</p>
  
  <pre><code>Access to fetch at 'https://xxxxx.execute-api.us-west-2.amazonaws.com/prod/getuserprofile' from 
  origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' 
  header is present on the requested resource. If an opaque response serves your needs, set the 
  request's mode to 'no-cors' to fetch the resource with CORS disabled.
  </code></pre>
  
  <p>First I have checked if this method works using the Lambda test.</p>
  
  <p>I have also used <code>curl -v -X OPTIONS https://xxxx.execute-api.us-west-2.amazonaws.com/prod/getuserprofile</code> and its output was: </p>
  
  <pre><code>`&lt; HTTP/2 200
  &lt; date: 
  &lt; content-type: application/json
  &lt; content-length: 0
  &lt; x-amzn-requestid:
  &lt; access-control-allow-origin: *
  &lt; access-control-allow-headers: Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token
  &lt; x-amz-apigw-id:
  &lt; access-control-allow-methods: DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT`
  </code></pre>
  
  <p>However, when I try the react.js fetch function it throws the error.</p>
  
  <pre><code>fetch("https://xxxx.execute-api.us-west-2.amazonaws.com/prod/getuserprofile", {
    method: 'PUT',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    },      
    body: JSON.stringify({key1: email, name, message})
    })
    .then(response =&gt; response.json())
    .then(data =&gt; {
      console.log('Success:', data);
    })
    .catch((error) =&gt; {
      console.error('Error:', error);
  });
  </code></pre>
  
  <p>I have tried to add 'mode' inside the fetch function to no avail.
  Any debugging advice would really help as well. Thank you.</p>