I get 403 forbidden when making ajax request to lambda endpoint. It's likely to be a CORS Issue.
serverless.yml
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
handler.js
'use strict';
var request = require('request');
module.exports.weather = (event, context, callback) => {
request('http://api.openweathermap.org/data/2.5/weather?APPID=__ID__&lat=40.66&lon=-73.77', function (error, response, body) {
if (!error && response.statusCode == 200) {
const response = {
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*"
},
body: body
};
callback(null, response);
}
});
};
```
I tried to enable CORS in API gateway, but I get invalid response code error.
Can you suggest how to fix the error and what could be causing it?
