LoginSignup
5
2

More than 3 years have passed since last update.

【AWS】CloudFrontのBehaviorsを使った分岐でハマったところ

Posted at

とりあえずメモレベルで残す

装飾とかまとめはまた別途書きます。

やりたかったこと

Route53に登録したホストゾーンのドメインに対して、URLから判定してS3かAPIGatewayに飛ばす

  • Default (*)の場合はS3(Staticページ)に飛ばす
  • /api/*の場合はAPIGatewayに飛ばす

ハマったところ

  • APIGatewayのStageがdevを設定
  • CloudFrontのOriginsに設定したAPIGatewayの設定のOrigin Path/devを設定
  • CloudFrontBehaviorsPath Patternには/api/*されていた
  • <cloud front path>/api/*でAPI叩いたら"message": "Missing Authentication Token"が返ってきた

原因

  • 上記の設定だと、APIGatewayの/api/dev/Stageにアクセスしようとするため、リソースがないと言われる
    • CloudFrontのBehaviorsPath Patternに設定する値と、APIGatewayのStageが一致している必要がある
    • CloudFrontのOriginsに設定したAPIGatewayの設定のOrigin Pathの値は設定しない

対応

  • APIGatewayのStageにapiを追加
  • CloudFrontのBehaviorsPath Pattern/api/*を設定
  • CloudFrontのOriginsOrigin Pathの設定値はなし

参照ページ

“Missing Authentication Token” — CloudFront/APIG Troubleshooting

5
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
5
2