8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CloudFrontとS3のCORS設定

Posted at

##CloudFrontとS3のCORS設定でハマる…

  • 端末、使用ブラウザよってエラーになったりならなかったり
  • 時間がない、色々調べるのに手が回らない
  • 見よう見まねでやるもうまくいかず
  • とりあえず、良くなった方法を書いてみる

###S3 バケットの設定
プロパティ > アクセス許可 > CORS設定の追加(編集)

CORS設定の追加(編集)
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>http://www.example.com</AllowedOrigin>
        <AllowedOrigin>https://www.example.com</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>HEAD</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

###ClowdFrontの設定
Distributions > Distribution Settings > Behaviors > Edit

  • 『forward headers』へ『Origin』を追加

###確認

CURLコマンド
curl -I -s -X GET -H "Origin: www.example.com" http://example.cloudfront.net/test.jpg

Chrome
デベロッパー ツール > NetWork
varyの項目を表示させて『Origin』となってればOK

8
9
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
8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?