【S3のアクセス権限】This XML file does not appear to have any style information associated with it. The document tree is shown below.【CloudFront使ってない版】

今回はThis XML file does not appear to have any style information associated with it. The document tree is shown below.のS3の権限へのエラー対応の紹介です。
目次
This XML file does not appear to have any style information associated with it. The document tree is shown below.とは?
「This XML file does not appear to have any style information associated with it. The document tree is shown below.」とは、Access Denied(アクセス拒否)」エラーです。
アクセスしようとしたS3バケットやオブジェクトに対するアクセス権限が不足していることが原因です。
This XML file does not appear to have any style information associated with it. The document tree is shown below.

This XML file does not appear to have any style information associated with it. The document tree is shown below.の対応方法

対応方法は結論、バケットポリシーの設定を変更します。
※CloudFront使用してない場合
現在の設定
- 許可対象:
arn:aws:iam::974728338576:user/S3Access
という特定のIAMユーザーに対して、バケット全体 (hoge-app
) とその中の全てのオブジェクト (hoge-app/*
) への 全てのS3アクション (s3:*
) を許可しています。 - 効果: このポリシーは、指定されたIAMユーザーにのみ、S3の全ての操作(読み取り、書き込み、削除など)を許可しています。
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::974728338576:user/S3Access"
},
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::hoge-app",
"arn:aws:s3:::hoge-app/*"
]
}
]
}
- 他のユーザーやパブリックアクセスは許可されていません。
スポンサードサーチ
変更後の設定
- 許可対象1: 最初のステートメントは1つ目のポリシーと同様に、特定のIAMユーザー (
arn:aws:iam::974728338576:user/S3Access
) に対してバケット全体への全てのS3操作を許可しています。 - 許可対象2: 追加されたステートメントで、すべてのユーザー(
Principal: "*"
)に対して、S3バケット内のオブジェクト (hoge-app/*
) への 読み取り操作(s3:GetObject
)を許可しています。
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::974728338576:user/S3Access"
},
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::hoge-app",
"arn:aws:s3:::hoge-app/*"
]
},
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::hoge-app/*"
}
]
}
- 指定のIAMユーザーには引き続き全ての操作が許可されています。
- すべてのユーザー(パブリック) が、バケット内のオブジェクトに対して
s3:GetObject
、つまりファイルのダウンロードが可能になります。ブラウザでの閲覧やファイルの取得がすべてのユーザーに許可されています。
まとめ
- 1つ目のポリシー: 特定のIAMユーザーのみがS3バケット全体への操作を行えるポリシー。
- 2つ目のポリシー: 特定のIAMユーザーはすべての操作が可能で、さらに パブリック(すべてのユーザー) にバケット内のオブジェクトへの読み取りアクセス(ダウンロード)が許可されているポリシー。

ブラウザでの閲覧をパブリックにしたい場合は、2つ目のポリシーを使うのが適切です。