Ruby、Solidus、Rails、AWS、Herokuの知識が少なく、手詰まりとなっています。
調べ方や「自分ならこれを試してみる」といった情報でも頂けると嬉しいです。
足りない情報がありましたら教えてください。
前提・実現したいこと
Solidusフレームワークを利用したECサイトを作成しようと考えています。
Herokuでは画像ファイルがサーバー再起動時に削除されてしまうので、S3に商品画像をアップロードしたいです。
SolidusのWikiをもとに設定し、管理画面からアップロードするとAccess Denied(403 Forbidden)のエラーが発生し、バケットには画像がアップロードされていません。
対象のIAMユーザーが含まれるグループにはAmazonS3FullAccessポリシーをアタッチしています。
発生している問題・エラーメッセージ
管理画面から画像をアップロードしようとしたときのスクリーンショットは以下になります。
Server failed to process the imageと表示されています。
HerokuのLogは以下のようになっており、403 Forbiddenと出ています。
HerokuLogs
1$ heroku logs -t 22019-01-21T09:14:20.223476+00:00 app[web.1]: [paperclip] saving spree/images/attachments/000/000/049/original/test.png 32019-01-21T09:14:27.338762+00:00 heroku[router]: at=info method=POST path="/admin/products/test/images" host=example.herokuapp.com request_id=... fwd=... dyno=web.1 connect=0ms service=16483ms status=500 bytes=1827 protocol=https 42019-01-21T09:14:27.334216+00:00 app[web.1]: (1.6ms) ROLLBACK 52019-01-21T09:14:27.334891+00:00 app[web.1]: Completed 500 Internal Server Error in 8295ms (ActiveRecord: 38.0ms) 62019-01-21T09:14:27.337274+00:00 app[web.1]: 72019-01-21T09:14:27.337315+00:00 app[web.1]: Excon::Error::Forbidden (Expected(200) <=> Actual(403 Forbidden) 82019-01-21T09:14:27.337318+00:00 app[web.1]: excon.error.response 92019-01-21T09:14:27.337320+00:00 app[web.1]: :body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>...</RequestId><HostId>...</HostId></Error>" 102019-01-21T09:14:27.337322+00:00 app[web.1]: :cookies => [ 112019-01-21T09:14:27.337323+00:00 app[web.1]: ] 122019-01-21T09:14:27.337325+00:00 app[web.1]: :headers => { 132019-01-21T09:14:27.337326+00:00 app[web.1]: "Connection" => "close" 142019-01-21T09:14:27.337328+00:00 app[web.1]: "Content-Type" => "application/xml" 152019-01-21T09:14:27.337330+00:00 app[web.1]: "Date" => "Mon, 21 Jan 2019 09:14:25 GMT" 162019-01-21T09:14:27.337331+00:00 app[web.1]: "Server" => "AmazonS3" 172019-01-21T09:14:27.337333+00:00 app[web.1]: "x-amz-id-2" => ... 182019-01-21T09:14:27.337334+00:00 app[web.1]: "x-amz-request-id" => ... 192019-01-21T09:14:27.337336+00:00 app[web.1]: } 202019-01-21T09:14:27.337337+00:00 app[web.1]: :host => "example.s3-ap-northeast-1.amazonaws.com" 212019-01-21T09:14:27.337339+00:00 app[web.1]: :local_address => ... 222019-01-21T09:14:27.337340+00:00 app[web.1]: :local_port => ... 232019-01-21T09:14:27.337342+00:00 app[web.1]: :path => "/spree/images/attachments/000/000/049/original/test.png" 242019-01-21T09:14:27.337344+00:00 app[web.1]: :port => 443 252019-01-21T09:14:27.337346+00:00 app[web.1]: :reason_phrase => "Forbidden" 262019-01-21T09:14:27.337347+00:00 app[web.1]: :remote_ip => ... 272019-01-21T09:14:27.337349+00:00 app[web.1]: :status => 403 282019-01-21T09:14:27.337351+00:00 app[web.1]: :status_line => "HTTP/1.1 403 Forbidden\r\n" 292019-01-21T09:14:27.337352+00:00 app[web.1]: ): 30
該当のソースコード
ruby
1#config/initializer/paperclip.rb 2 3if ENV['AWS_ACCESS_KEY_ID'] 4 Paperclip::Attachment.default_options.merge!( 5 storage: :fog, 6 fog_credentials: { 7 provider: 'AWS', 8 aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'], 9 aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'], 10 region: ENV['S3_REGION_NAME'] 11 }, 12 fog_directory: ENV["S3_BUCKET_NAME"] 13 ) 14 15 Spree::Image.attachment_definitions[:attachment].delete(:url) 16 Spree::Image.attachment_definitions[:attachment].delete(:path) 17end
試したこと
paperclip.rbファイルのENV[]と記載されている部分を直書きしてみる→同じエラーが発生
awscliをインストールし、同じアクセスキーID、シークレット、リージョン名、バケット名で同じファイルをアップロードしてみる
→成功。ただし--acl public-readオプションを追加すると失敗。
CLI
1$ aws s3 cp test.png s3://example/ --profile=default 2upload: ./test.png to s3://example/test.png 3$ aws s3 cp test.png s3://example/ --profile=default --acl public-read 4upload failed: ./test.png to s3://example/test.png An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
対象のIAMユーザーにAdministratorAccessポリシーをアタッチして再度アップロードをしてみる→同じエラーが発生
補足情報(FW/ツールのバージョンなど)
Gemfile
1source 'https://rubygems.org' 2git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4ruby '2.4.1' 5 6# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 7gem 'rails', '~> 5.2.0' 8# Use Puma as the app server 9gem 'puma', '~> 3.11' 10# Use SCSS for stylesheets 11gem 'sass-rails', '~> 5.0' 12# Use Uglifier as compressor for JavaScript assets 13gem 'uglifier', '>= 1.3.0' 14# See https://github.com/rails/execjs#readme for more supported runtimes 15# gem 'mini_racer', platforms: :ruby 16 17# Use CoffeeScript for .coffee assets and views 18gem 'coffee-rails', '~> 4.2' 19# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 20gem 'turbolinks', '~> 5' 21# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 22gem 'jbuilder', '~> 2.5' 23# Use Redis adapter to run Action Cable in production 24# gem 'redis', '~> 4.0' 25# Use ActiveModel has_secure_password 26# gem 'bcrypt', '~> 3.1.7' 27 28# Use ActiveStorage variant 29# gem 'mini_magick', '~> 4.8' 30 31# Use Capistrano for deployment 32# gem 'capistrano-rails', group: :development 33 34# Reduces boot times through caching; required in config/boot.rb 35gem 'bootsnap', '>= 1.1.0', require: false 36 37group :development, :test do 38 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 39 gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 40end 41 42group :development do 43 # Access an interactive console on exception pages or by calling 'console' anywhere in the code. 44 gem 'web-console', '>= 3.3.0' 45 gem 'listen', '>= 3.0.5', '< 3.2' 46 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 47 gem 'spring' 48 gem 'spring-watcher-listen', '~> 2.0.0' 49 # Use sqlite3 as the database for Active Record 50 gem 'sqlite3' 51end 52 53group :test do 54 # Adds support for Capybara system testing and selenium driver 55 gem 'capybara', '>= 2.15', '< 4.0' 56 gem 'selenium-webdriver' 57 # Easy installation and use of chromedriver to run system tests with Chrome 58 gem 'chromedriver-helper' 59end 60 61group :production do 62 gem 'pg', '0.20.0' 63 gem 'rails_12factor' 64end 65 66gem 'paperclip' 67gem 'solidus' 68gem 'solidus_auth_devise' 69gem 'fog-aws' 70 71# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 72gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 73

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。