I have a React application and trying to access to serverless from aws. But I have below error
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www.test.com' is therefore not allowed access. The response had HTTP status code 502.
End point url is https://key.execute-api.ap-southeast-2.amazonaws.com/dev/samplefunction
Setting on serverless.yml is
login:
handler: login.login
events:
- http:
path: login
method: post
cors:
origin: 'https://admin.differentdomain.com'
headers:
- MY_CUSTOM_HEADER
- Content-Type
- X-Amz-Date
- Authorization
- X-Api-Key
- X-Amz-Security-Token
Is there any other place I need to do CORS configuration?
Access-Control-Allow-Originheader to the response. I don't think there's anywhere else in your serverless template you need to put CORS related items. - Mike Patrickcallbackneeds to supply this header. So instead of{statusCode: 200, body: {} }, you want{statusCode: 200, headers: {Access-Control-Allow-Origin: "*"}, body: {} }. Assuming you're using lambda proxy integration. - Mike PatrickallowCredentials: trueundercors:instead of just doingcors: true. Adding the header in your code is also needed, so keep that. But that isn't even invoked for the preflight CORS requests, so you need this one in addition. - V Maharajh