PermanentRedirect异常:aws-sdk s3 Rails 5

时间:2016-12-10 01:20:50

标签: ruby-on-rails ruby amazon-web-services amazon-s3 aws-sdk

我尝试列出或检索亚马逊存储桶中的对象,并且我不断收到此错误消息:

(byebug) resp = s3.list_objects(bucket:'mp3list')
*** Aws::S3::Errors::PermanentRedirect Exception: 
The bucket you are attempting to access must be addressed 
using the specified endpoint. 
Please send all future requests to this endpoint.

我可以毫无问题地从同一个文件夹上传和删除文件。

有人知道如何指定该端点吗?在哪里?

我对s3存储桶的配置:

Bucket: mp3play
Region: Frankfurt
Creation Date:  Fri Dec 09 17:44:39 GMT+100 2016
Owner: aaa

Can list, upload, delete.

aws.rb>

Aws.config.update({
  credentials: Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY']),
  region: 'eu-central-1'
})

# list buckets in Amazon S3
s3 = Aws::S3::Client.new
resp = s3.list_buckets
S3_BUCKET = resp.buckets[0]
resp.buckets.map(&:name)

S3 = Aws::S3::Resource.new(region: 'eu-central-1')

1 个答案:

答案 0 :(得分:1)

endpoint键添加到config:

Aws.config.update({
  credentials: Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY']),
  region: 'eu-central-1',
  endpoint:'https://s3.eu-central-1.amazonaws.com'
})

按地区划分的可用终端列表:http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region