Help us understand the problem. What is going on with this article?

Rails5 heroku にS3を使ってアップロードしたときに発生するエラー 403 Access denied の対処法

背景

S3にあるリソースはデフォルトでは外部からアクセスできないようになっている.
Heroku上で動いているアプリで画像をアップロードしても,403 errorではじかれて,表示できない.

やったこと

パブリックアクセス設定を一度すべてオフにする

Screen Shot 2019-11-24 at 4.20.26 PM.png

バケットポリシーを作成

アクセス権限→バケットポリシーを選択すると,編集画面になるので,以下の内容を書く.
Screen Shot 2019-11-24 at 4.25.42 PM.png

{
    "Version": "2012-10-17",
    "Id": "PublicRead",
    "Statement": [
        {
            "Sid": "ReadAccess",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::<あなたのAWS12桁のID>:user/<IAMユーザー名>"
            },
            "Action": "*",
            "Resource": "arn:aws:s3:::<bucketの名前>/*"
        }
    ]
}

パブリックアクセス設定を変えて,新しいバケットポリシーをブロックさせる

念の為.ブロックさせるようにする.
Screen Shot 2019-11-24 at 4.15.00 PM.png

参考

https://qiita.com/rainbow___0/items/0ffeb29afc7865eb65b5
https://teratail.com/questions/170083

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away