前提・実現したいこと
CloudfrontでのBehaviorsでのパスの振り分けを行いたいです。
CloudFrontに向かってくるパスに応じてALBとS3で振り分けを行いたいです。
流れは自分で作成をしてみてその後に
https://qiita.com/keitakn/items/35ae8cc56f5c0a4766b4
を参考にしてOAIの設定を行いました。
アクセス周りでの設定がおかしいと思うのですが、原因の特定ができないです。
何かわかることをご教授できたら幸いです。
パスパターンは
Default () >ALB
mv-s3/ >S3にはSPA(Angular)で作成した静的webサイトがホストされてます。
S3のバケットに直接アクセス(bucket-name.s3.region.amazonaws.com)するとSPAが表示されます。
僕の認識ではRestrict Bucket AccessをONにするとS3はクラウドフロントからのみアクセスができるという認識なのですが、思っている挙動ではないです。
となるとS3のポリシーが間違っているということですか?
何かここを確認した方がいいとかありましたらお願いします。
発生している問題・エラーメッセージ
$ curl -sLI cloudfront.net HTTP/1.1 200 OK $ curl -sLI cloudfront.net/mv-s3/ HTTP/1.1 403 Forbidden Content-Type: application/xml Connection: keep-alive Server: AmazonS3 X-Cache: Error from cloudfront
ブラウザから確認をすると以下のようになります。
<Error> <Code>AccessDenied</Code> <Message>Access Denied</Message> </Error>
S3バケットポリシー
以下のバケットのポリシーからS3に直接アクセスできます。
ここでは定義がおかしいのか、反映がされていないのか分かってないです。
{ "Version": "2012-10-17", "Statement": [ { "Sid": "1", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity OAI" }, "Action": "s3:GetObject", "Resource": "arn:aws:s3:::bucket/*" } ] }
行ったこと、疑問
公式を参考にすると、
When you specify the Amazon S3 bucket that you want CloudFront to get objects from, we recommend that you use the following format to access the bucket:
bucket-name.s3.region.amazonaws.com
Another option might be to use the following more general format, but be aware that this format doesn't work for Regions launched in 2019 or later:
bucket-name.s3.amazonaws.com
とありました。
CloudFrontでオリジンを設定するときにbucket-name.s3.amazonaws.comのフォーマットの指定しかできなかったのですが、
これが実際に原因なのか分かってないです。
その後に
When you specify the bucket name in this format, you can use the following CloudFront features:
Configure CloudFront to communicate with your Amazon S3 bucket using SSL. For more information, see Using HTTPS with CloudFront.
ということで、CloudFrontにSSLの証明書をアタッチすれば解決するということなのでしょうか?
そもそもでなぜ、
S3の公開はbucket-name.s3.region.amazonaws.com
なのに、CloudFrontから指定するオリジンのところで、bucket-name.s3.amazonaws.com
しか指定できないのですか?
何かわかることや、認識が間違っていることがあれば教えていただけると嬉しいです。
あなたの回答
tips
プレビュー