1

I am using serverless to deploy my service. This is how i am configuring a lambda function

hello:
  handler: handler.hello
  events:
    - http:
        path: /hello
        method: get
        cors: true
        authorizer: aws_iam

Also i am using AWS cognito to authorise logged in user. The same user credentials are working for other serverless services but for this one. we are sending proper response headers as well as mentioned in some other solutions. I have tried almost everything i could find.

This is the error i am getting (Though option call is giving 200).

Access to fetch at 'https://*******.execute-api.us-east-2.amazonaws.com/dev/hello' from origin 'http://***.ngrok.io' 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.

I would appreciate your help. Please comment if any other information is required for you to understand my problem.

Thanks a lot.

Nidhi Agarwal
  • 316
  • 2
  • 13

1 Answers1

-1

you should return access-control-allow-Origin from lambda resposne as well.

In python it is something like this

return {'statusCode': status_code, 
'body': response, 
'isBase64Encoded': False, 
'headers':{ 'Access-Control-Allow-Origin': 'http://localhost:3000'}}

more about it here

best wishes
  • 5,789
  • 1
  • 34
  • 59
  • In my case this was not the issue. I was using query params ... that was causing url mismatch issue. I could not find a way to use query params in lamda proxy integration so for now i just removed them from my urls. – Nidhi Agarwal Feb 10 '19 at 08:17