title: How to make lambda work with ajax?
body: <p>I get 403 forbidden when making ajax request to lambda endpoint.
  It's likely to be a CORS Issue.</p>
  
  <p><strong>serverless.yml</strong></p>
  
  <pre><code>    service: aws-nodejs # NOTE: update this with your service name
      provider:
      name: aws
      runtime: nodejs4.3
  
      functions:
      weather:
          handler: handler.weather
          events:
              - http:
                  path: weather
                  method: get
                  cors: true
  </code></pre>
  
  <p><strong>handler.js</strong>        </p>
  
  <pre><code>'use strict';
  
      var request = require('request');
  
      module.exports.weather = (event, context, callback) =&gt; {
          request('http://api.openweathermap.org/data/2.5/weather?APPID=__ID__&amp;lat=40.66&amp;lon=-73.77', function (error, response, body) {
              if (!error &amp;&amp; response.statusCode == 200) {
                  const response = {
                      statusCode: 200,
                      headers: {
                          "Content-Type": "application/json",
                          "Access-Control-Allow-Origin": "*"
                      },
                      body: body
                  };
                  callback(null, response);
              }
          });
      };
  </code></pre>
  
  <p>```</p>
  
  <p>I tried to enable CORS in API gateway, but I get invalid response code error.</p>
  
  <p><a href="https://i.stack.imgur.com/dmscY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dmscY.png" alt="enter image description here"></a></p>
  
  <p>Can you suggest how to fix the error and what could be causing it? </p>