Amazon S3 Bucket 403 Forbidden

时间:2015-01-29 11:04:25

标签: mysql ruby-on-rails heroku amazon-s3

我正在关注Michael Hartl的Rails教程,我试图让用户能够上传图像。它在rails服务器上工作正常,但是当我部署到Heroku时,它使用S3来处理图像。上传失败,出现403错误。这是日志:

2015-01-29T10:31:39.129339+00:00 app[web.1]:    (2.0ms)  SELECT COUNT(*) FROM "microposts" WHERE (user_id = 101)
2015-01-29T10:31:39.125076+00:00 app[web.1]:   Rendered shared/_error_messages.html.erb (0.1ms)
2015-01-29T10:31:39.138938+00:00 app[web.1]:   CACHE (0.0ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1  [["id", 101]]
2015-01-29T10:31:39.155276+00:00 app[web.1]:   Rendered shared/_feed.html.erb (28.9ms)
2015-01-29T10:31:39.169708+00:00 app[web.1]:   Rendered layouts/_shim.html.erb (0.1ms)
2015-01-29T10:31:39.183946+00:00 app[web.1]:   Rendered layouts/_footer.html.erb (0.1ms)
2015-01-29T10:31:39.197655+00:00 heroku[router]: at=info method=GET path="/" host=mysterious-oasis-7816.herokuapp.com request_id=4c2cbe41-3b26-4e37-9ef9-f07ec6e963a6 fwd="76.102.7.62" dyno=web.1 connect=3ms service=109ms status=200 bytes=4525
2015-01-29T10:31:39.369193+00:00 heroku[router]: at=info method=GET path="/assets/application-3ac07d30cc871c78233de32e71487cf3.js" host=mysterious-oasis-7816.herokuapp.com request_id=6cd2bfa0-424b-4456-9cfb-822b515d3bcc fwd="76.102.7.62" dyno=web.1 connect=1ms service=4ms status=304 bytes=241
2015-01-29T10:31:39.365503+00:00 heroku[router]: at=info method=GET path="/assets/application-cbf43ddf42ea7f553995264124e0cacf.css" host=mysterious-oasis-7816.herokuapp.com request_id=d7df3d86-0cf4-444b-bce8-8b164c2dbef6 fwd="76.102.7.62" dyno=web.1 connect=1ms service=3ms status=304 bytes=227
2015-01-29T10:31:39.598181+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=mysterious-oasis-7816.herokuapp.com request_id=386ad300-9cd9-43e7-8112-f918d7c3a7df fwd="76.102.7.62" dyno=web.1 connect=2ms service=2ms status=304 bytes=156
2015-01-29T10:31:46.517236+00:00 app[web.1]: Started POST "/microposts" for 76.102.7.62 at 2015-01-29 10:31:46 +0000
2015-01-29T10:31:46.519545+00:00 app[web.1]: Processing by MicropostsController#create as HTML
2015-01-29T10:31:46.519617+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"p60LlipkvgDwLSAR8oJq+efj9yM0jYixbkwxWxN2v3sojEQFzbMhTVio4pXOwZehVpGQYfgYdnKgHRQomE/txg==", "micropost"=>{"content"=>"Sup", "picture"=>#<ActionDispatch::Http::UploadedFile:0x007f77ae5d1d80 @tempfile=#<Tempfile:/tmp/RackMultipart20150129-12-b07k07.jpg>, @original_filename="10582291_709123052488481_30008247_n.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"micropost[picture]\"; filename=\"10582291_709123052488481_30008247_n.jpg\"\r\nContent-Type: image/jpeg\r\n">}, "commit"=>"Post"}
2015-01-29T10:31:46.521720+00:00 app[web.1]:   User Load (1.2ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1  [["id", 101]]
2015-01-29T10:31:46.836156+00:00 app[web.1]:    (1.5ms)  BEGIN
2015-01-29T10:31:46.841095+00:00 app[web.1]:   SQL (1.7ms)  INSERT INTO "microposts" ("content", "picture", "user_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id"  [["content", "Sup"], ["picture", "10582291_709123052488481_30008247_n.jpg"], ["user_id", 101], ["created_at", "201
5-01-29 10:31:46.837765"], ["updated_at", "2015-01-29 10:31:46.837765"]]
2015-01-29T10:31:48.433575+00:00 heroku[router]: at=info method=POST path="/microposts" host=mysterious-oasis-7816.herokuapp.com request_id=d7e1b8ee-3e5d-45ef-9578-4f242fd160db fwd="76.102.7.62" dyno=web.1 connect=1ms service=2239ms status=500 bytes=1786
2015-01-29T10:31:48.427961+00:00 app[web.1]:    (1.3ms)  ROLLBACK
2015-01-29T10:31:48.431863+00:00 app[web.1]: 
2015-01-29T10:31:48.431866+00:00 app[web.1]: Excon::Errors::Forbidden (Expected(200) <=> Actual(403 Forbidden)
2015-01-29T10:31:48.431868+00:00 app[web.1]: excon.error.response
2015-01-29T10:31:48.431870+00:00 app[web.1]:   :body          => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>2E3F56207B398181</RequestId><HostId>XIDq0YLLZd8ZdGB1mTuUiofj5vh0V4lt5hb/jow79dysteI26fEr/gNMpGqF5qCv0zPmFiEYtCY=</HostId></Error>"
2015-01-29T10:31:48.431871+00:00 app[web.1]:   :headers       => {
2015-01-29T10:31:48.431873+00:00 app[web.1]:     "Connection"       => "close"
2015-01-29T10:31:48.431874+00:00 app[web.1]:     "Content-Type"     => "application/xml"
2015-01-29T10:31:48.431875+00:00 app[web.1]:     "Date"             => "Thu, 29 Jan 2015 10:31:47 GMT"
2015-01-29T10:31:48.431878+00:00 app[web.1]:     "x-amz-id-2"       => "XIDq0YLLZd8ZdGB1mTuUiofj5vh0V4lt5hb/jow79dysteI26fEr/gNMpGqF5qCv0zPmFiEYtCY="
2015-01-29T10:31:48.431879+00:00 app[web.1]:     "x-amz-request-id" => "2E3F56207B398181"
2015-01-29T10:31:48.431881+00:00 app[web.1]:   }
2015-01-29T10:31:48.431882+00:00 app[web.1]:   :local_address => "172.17.38.98"
2015-01-29T10:31:48.431883+00:00 app[web.1]:   :local_port    => 34183
2015-01-29T10:31:48.431885+00:00 app[web.1]:   :reason_phrase => "Forbidden"
2015-01-29T10:31:48.431877+00:00 app[web.1]:     "Server"           => "AmazonS3"
2015-01-29T10:31:48.431890+00:00 app[web.1]:   app/controllers/microposts_controller.rb:7:in `create'
2015-01-29T10:31:48.431891+00:00 app[web.1]: 
2015-01-29T10:31:48.431892+00:00 app[web.1]: 
2015-01-29T10:31:48.431886+00:00 app[web.1]:   :remote_ip     => "54.231.160.162"
2015-01-29T10:31:48.431887+00:00 app[web.1]:   :status        => 403
2015-01-29T10:31:48.431889+00:00 app[web.1]: ):
2015-01-29T10:31:48.429838+00:00 app[web.1]: Completed 500 Internal Server Error in 1910ms
2015-01-29T10:46:55.496986+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=mysterious-oasis-7816.herokuapp.com request_id=2a227f3f-20da-405f-b150-f4e4cbc62c0c fwd="76.102.7.62" dyno=web.1 connect=1ms service=1ms status=304 bytes=156
2015-01-29T10:46:57.592699+00:00 app[web.1]: Processing by MicropostsController#create as HTML
2015-01-29T10:46:57.592801+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"p60LlipkvgDwLSAR8oJq+efj9yM0jYixbkwxWxN2v3sojEQFzbMhTVio4pXOwZehVpGQYfgYdnKgHRQomE/txg==", "micropost"=>{"content"=>"Sup", "picture"=>#<ActionDispatch::Http::UploadedFile:0x007f77b148e678 @tempfile=#<Tempfile:/tmp/RackMultipart20150129-6-kbjdeu.jpg>, @original_filename="10582291_709123052488481_30008247_n.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"micropost[picture]\"; filename=\"10582291_709123052488481_30008247_n.jpg\"\r\nContent-Type: image/jpeg\r\n">}, "commit"=>"Post"}
2015-01-29T10:46:57.595260+00:00 app[web.1]:   User Load (1.3ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1  [["id", 101]]
2015-01-29T10:46:57.589391+00:00 app[web.1]: Started POST "/microposts" for 76.102.7.62 at 2015-01-29 10:46:57 +0000
2015-01-29T10:46:57.898731+00:00 app[web.1]:    (1.4ms)  BEGIN
2015-01-29T10:46:57.906703+00:00 app[web.1]:   SQL (2.1ms)  INSERT INTO "microposts" ("content", "picture", "user_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id"  [["content", "Sup"], ["picture", "10582291_709123052488481_30008247_n.jpg"], ["user_id", 101], ["created_at", "2015-01-29 10:46:57.900611"], ["updated_at", "2015-01-29 10:46:57.900611"]]
2015-01-29T10:46:59.548010+00:00 heroku[router]: at=info method=POST path="/microposts" host=mysterious-oasis-7816.herokuapp.com request_id=e7867249-ff62-4fa0-bf0e-9dadd9134640 fwd="76.102.7.62" dyno=web.1 connect=1ms service=2273ms status=500 bytes=1786
2015-01-29T10:46:59.542346+00:00 app[web.1]:    (1.4ms)  ROLLBACK
2015-01-29T10:46:59.546576+00:00 app[web.1]: 
2015-01-29T10:46:59.546579+00:00 app[web.1]: Excon::Errors::Forbidden (Expected(200) <=> Actual(403 Forbidden)
2015-01-29T10:46:59.546581+00:00 app[web.1]: excon.error.response
2015-01-29T10:46:59.546583+00:00 app[web.1]:   :body          => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>6B6A73213C176F40</RequestId><HostId>QDnWZ627/2/Wuf7z4nuQnS/u+ysezUG/o2IqDnO9hgAJBJF+H3h4uexFerBeON2V</HostId></Error>"
2015-01-29T10:46:59.546584+00:00 app[web.1]:   :headers       => {
2015-01-29T10:46:59.546586+00:00 app[web.1]:     "Connection"       => "close"
2015-01-29T10:46:59.546587+00:00 app[web.1]:     "Content-Type"     => "application/xml"
2015-01-29T10:46:59.546589+00:00 app[web.1]:     "Date"             => "Thu, 29 Jan 2015 10:46:58 GMT"
2015-01-29T10:46:59.546591+00:00 app[web.1]:     "Server"           => "AmazonS3"
2015-01-29T10:46:59.546593+00:00 app[web.1]:     "x-amz-id-2"       => "QDnWZ627/2/Wuf7z4nuQnS/u+ysezUG/o2IqDnO9hgAJBJF+H3h4uexFerBeON2V"
2015-01-29T10:46:59.546594+00:00 app[web.1]:     "x-amz-request-id" => "6B6A73213C176F40"
2015-01-29T10:46:59.546595+00:00 app[web.1]:   }
2015-01-29T10:46:59.546597+00:00 app[web.1]:   :local_address => "172.17.38.98"
2015-01-29T10:46:59.546598+00:00 app[web.1]:   :local_port    => 47100
2015-01-29T10:46:59.546601+00:00 app[web.1]:   :remote_ip     => "54.231.164.162"
2015-01-29T10:46:59.546600+00:00 app[web.1]:   :reason_phrase => "Forbidden"
2015-01-29T10:46:59.546603+00:00 app[web.1]:   :status        => 403
2015-01-29T10:46:59.546604+00:00 app[web.1]: ):
2015-01-29T10:46:59.546606+00:00 app[web.1]:   app/controllers/microposts_controller.rb:7:in `create'
2015-01-29T10:46:59.546607+00:00 app[web.1]: 
2015-01-29T10:46:59.546608+00:00 app[web.1]: 
2015-01-29T10:46:59.544420+00:00 app[web.1]: Completed 500 Internal Server Error in 1951ms
2015-01-29T10:47:51.464274+00:00 app[web.1]: Started POST "/microposts" for 76.102.7.62 at 2015-01-29 10:47:51 +0000
2015-01-29T10:47:51.468398+00:00 app[web.1]: Processing by MicropostsController#create as HTML
2015-01-29T10:47:51.473171+00:00 app[web.1]:   User Load (1.4ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1  [["id", 101]]
2015-01-29T10:47:51.468507+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"p60LlipkvgDwLSAR8oJq+efj9yM0jYixbkwxWxN2v3sojEQFzbMhTVio4pXOwZehVpGQYfgYdnKgHRQomE/txg==", "micropost"=>{"content"=>"Sup", "picture"=>#<ActionDispatch::Http::UploadedFile:0x007f77ae6c1358 @tempfile=#<Tempfile:/tmp/RackMultipart20150129-9-6wmavu.jpg>, @original_filename="10582291_709123052488481_30008247_n.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"micropost[picture]\"; filename=\"10582291_709123052488481_30008247_n.jpg\"\r\nContent-Type: image/jpeg\r\n">}, "commit"=>"Post"}
2015-01-29T10:47:51.786456+00:00 app[web.1]:    (1.4ms)  BEGIN
2015-01-29T10:47:51.794299+00:00 app[web.1]:   SQL (2.0ms)  INSERT INTO "microposts" ("content", "picture", "user_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id"  [["content", "Sup"], ["picture", "10582291_709123052488481_30008247_n.jpg"], ["user_id", 101], ["created_at", "2015-01-29 10:47:51.788551"], ["updated_at", "2015-01-29 10:47:51.788551"]]
2015-01-29T10:47:53.555368+00:00 heroku[router]: at=info method=POST path="/microposts" host=mysterious-oasis-7816.herokuapp.com request_id=86847ddb-74ec-4800-a18f-a07f2431cef9 fwd="76.102.7.62" dyno=web.1 connect=1ms service=2197ms status=500 bytes=1786
2015-01-29T10:47:53.550620+00:00 app[web.1]:    (1.3ms)  ROLLBACK
2015-01-29T10:47:53.554579+00:00 app[web.1]: 
2015-01-29T10:47:53.554582+00:00 app[web.1]: Excon::Errors::Forbidden (Expected(200) <=> Actual(403 Forbidden)
2015-01-29T10:47:53.554584+00:00 app[web.1]: excon.error.response
2015-01-29T10:47:53.554587+00:00 app[web.1]:   :headers       => {
2015-01-29T10:47:53.554586+00:00 app[web.1]:   :body          => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>6A39B8D8600F9D09</RequestId><HostId>cRac47ERlbGbSfrsTNt/fF+zt5CvM7Io8HZXU5A27l207MleOMCsGIRdmElP0Kk4</HostId></Error>"
2015-01-29T10:47:53.554589+00:00 app[web.1]:     "Connection"       => "close"
2015-01-29T10:47:53.554590+00:00 app[web.1]:     "Content-Type"     => "application/xml"
2015-01-29T10:47:53.554593+00:00 app[web.1]:     "Server"           => "AmazonS3"
2015-01-29T10:47:53.554592+00:00 app[web.1]:     "Date"             => "Thu, 29 Jan 2015 10:47:53 GMT"
2015-01-29T10:47:53.554595+00:00 app[web.1]:     "x-amz-id-2"       => "cRac47ERlbGbSfrsTNt/fF+zt5CvM7Io8HZXU5A27l207MleOMCsGIRdmElP0Kk4"
2015-01-29T10:47:53.554612+00:00 app[web.1]:     "x-amz-request-id" => "6A39B8D8600F9D09"
2015-01-29T10:47:53.554613+00:00 app[web.1]:   }
2015-01-29T10:47:53.554619+00:00 app[web.1]:   :remote_ip     => "54.231.165.74"
2015-01-29T10:47:53.554620+00:00 app[web.1]:   :status        => 403
2015-01-29T10:47:53.554623+00:00 app[web.1]:   app/controllers/microposts_controller.rb:7:in `create'
2015-01-29T10:47:53.554622+00:00 app[web.1]: ):
2015-01-29T10:47:53.554615+00:00 app[web.1]:   :local_address => "172.17.38.98"
2015-01-29T10:47:53.554616+00:00 app[web.1]:   :local_port    => 40757
2015-01-29T10:47:53.554618+00:00 app[web.1]:   :reason_phrase => "Forbidden"
2015-01-29T10:47:53.554625+00:00 app[web.1]: 
2015-01-29T10:47:53.554626+00:00 app[web.1]: 
2015-01-29T10:47:53.552507+00:00 app[web.1]: Completed 500 Internal Server Error in 2084ms

请帮助:(

2 个答案:

答案 0 :(得分:0)

我遇到了类似的问题,根据您创建存储区的区域,格式化网址的方式不同。

你有时可以使用这个: https://s3-us-west-2.amazonaws.com/

有时你必须使用这个: https://bucket-name.s3-us-west-2.amazonaws.com/

我不知道您使用的是哪种格式,但请尝试另一种格式:)

有关访问不同区域的网址的更多信息,请查看以下内容: http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteEndpoints.html

答案 1 :(得分:0)

感谢帮助人员,我明白了。事实证明这是非常愚蠢的事情,我没有将允许的用户设置为注册用户。