4
3

More than 1 year has passed since last update.

CloudFront + S3 で「This XML file does not appear to have any style information associated with it.」エラー

Posted at

はじめに

静的ファイルをS3に保存し、Cloudfront経由で公開しようとした際に、下記のエラーに出くわしました。
スクリーンショット 2022-01-29 22.19.36.png

  <Code>SignatureDoesNotMatch</Code>
  <Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
  <AWSAccessKeyId>*******</AWSAccessKeyId>

スクリーンショット 2022-01-29 22.17.31.png

原因

結論から言うと、CloudFrontのオリジンリクエストのキャッシュキーにHostヘッダーを追加していたことが原因でした。
Hostヘッダーを追加すると、OriginにHostヘッダーが転送されます。
スクリーンショット 2022-01-29 21.40.06.png

OriginにS3を設定した場合、S3バケットの特定にはHOSTヘッダーが使われます。
CloudFrontからS3へリクエストする際のHOSTヘッダーが、クライアントリクエストのHOSTヘッダーで上書きされてしまい、その結果として、S3バケットが見つからず、エラーになったというわけです。

スクリーンショット 2022-01-29 22.23.33.png

他にもオリジンリクエストポリシーのAllViewerやヘッダーのAuthorizationが追加されると同様に上書きされてしまい、エラーになります。
スクリーンショット 2022-01-29 21.40.18.png

同様に、CloudFront → ELB → EC2の構成の場合、
abcd.cloudfront.netでアクセスすると、同様のエラーが起きますね。

4
3
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
4
3