嗨,我正在使用下面的代码来获取存储桶的大小。进行了全面研究,但唯一的方法是循环遍历每个文件。在循环遍历时,一些存储桶似乎是在不同的区域创建的,我最终得到了上面错误
AWS::S3::PermanentRedirect: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. from /home//.rvm/gems/ruby-1.9.2-p180/gems/aws-s3-0.6.2/lib/aws/s3/error.rb:38:in `raise'
终点是 us-west-1,需要帮助解决上述问题以及如何将我的代码动态切换到我的存储桶所属的区域。在失败的情况下还需要添加异常的建议下面是我的代码。请随意发表评论。
def get_bucket
s3 = AWS::S3::Base.establish_connection!(:access_key_id => @config[:ACCESS_KEY_ID], :secret_access_key => @config[:SECRET_ACCESS_KEY])
if !s3.nil?
AWS::S3::Service.buckets.each do |bucket|
puts bucket.inspect
if !bucket.nil?
size = 0
# I'm harding coding below bucket names, for code not to fail
if ![
'cf-templates-m01ixtvp0jr0-us-west-1',
'cf-templates-m01ixtvp0jr0-us-west-2',
'elasticbeanstalk-us-west-1-767904627276',
'elasticbeanstalk-us-west-1-akiai7bucgnrthi66w6a',
'medidata-rave-cdn'
].include? bucket.name
bucket_size = AWS::S3::Bucket.find(bucket.name)
if !bucket_size.nil?
bucket_size.each do |obj|
if !obj.nil?
size += obj.size.to_i
end
end
end
end
load_bucket(bucket.name,bucket.creation_date,size,@config[:ACCOUNT_NAME])
end
end
end
end