LoginSignup
1
1

More than 1 year has passed since last update.

【AWS】API GWのOPTIONSで500エラー

Posted at

現象

API GW + Lambdaの構成で、API GWのCORSの有効化をしてOPTIOINSメソッドを作成しました。
ところが、CORSのpreflightリクエストでなぜか500エラーでInternal server errorが返ってきてしまいました。

$ curl -v -X OPTIONS -H 'Origin: http://localhost:3000' -H 'Access-Control-Request-Method: GET' -H 'Access-Control-Request-Headers: content-type' https://xxxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/Prod/hoge
~~~
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 500
< content-type: application/json
< content-length: 36
< date: Tue, 16 May 2023 04:30:26 GMT
< x-amzn-requestid: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
< x-amzn-errortype: InternalServerErrorException
< x-amz-apigw-id: E_xxxxxx
< x-cache: Error from cloudfront
< via: 1.1 xxxxxxxxxxxxxxxxx.cloudfront.net (CloudFront)
< x-amz-cf-pop: NRT57-P4
< x-amz-cf-id: xxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxx
<
* Connection #0 to host xxxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com left intact
{"message": "Internal server error"}

解決策

バイナリメディアタイプの*/*をやめる
image.png

原因

自分の場合は画像データを返すAPIがあったので、細かい事考えるのやめて*/*と設定したことが原因でした。
消したら動きましたし、image/*でも大丈夫でした。*/*がNGの模様。

1
1
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
1