LoginSignup
1
2

More than 3 years have passed since last update.

Lambda+APIGateway設定で「CORS の有効化」をオンにしたのにCORSエラーになる

Last updated at Posted at 2019-11-29

「CORS の有効化」をオンにしたのに

ハマりポイント

APIGateway設定で「CORS の有効化」をオンにしているのに,

Access to XMLHttpRequest at 'https://xxxxxxx.execute-api.ap-northeast-1.amazonaws.com/xxx/xxxx' from origin 'http://xxxxx' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

とエラーが返ってくる.

解決策

Lambdaのreturnのヘッダーに以下のように,Access-Contraolについて書かなきゃダメだった.

    return {
        'isBase64Encoded': False,
        "headers": {
            "Access-Control-Allow-Origin" : "*",
            "Access-Control-Allow-Credentials": "true"
        },
        'statusCode': 200,
        'body': {}
    }
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2