代码之家  ›  专栏  ›  技术社区  ›  Nidhi Agarwal

无服务器+Lambda+cognito CORS问题

  •  0
  • Nidhi Agarwal  · 技术社区  · 7 年前

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

    我还使用awscognito来授权登录的用户。相同的用户凭据适用于其他无服务器服务,但适用于此服务。我们正在发送正确的响应头以及一些其他解决方案中提到的。我几乎试过了所有能找到的东西。

    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.
    

    我会感激你的帮助。 如果您需要任何其他信息来理解我的问题,请发表意见。

    谢谢。

    1 回复  |  直到 7 年前
        1
  •  -1
  •   best wishes    7 年前

    你应该回来 access-control-allow-Origin 来自兰姆达·雷波斯。

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

    更多信息 here