访问我的AWS S3帐户的存储桶时出现问题

时间:2022-11-02 23:04:31

I tried to establish connection to my aws s3 account like this in my irb console -

我尝试在我的irb控制台中建立与我的aws s3帐户的连接 -

AWS::S3::Base.establish_connection!(:access_key_id => 'my access key', :secret_access_key => 'my secret key', :server => "s3-ap-southeast-1.amazonaws.com")

And it works well and prompt this -

它运作良好并提示 -

=> #<AWS::S3::Connection:0x8cd86d0 @options={:server=>"s3-ap-southeast-1.amazonaws.com", :port=>80, :access_key_id=>"my access key", :secret_access_key=>"my secret key"}, @access_key_id="my access key", @secret_access_key="my secret key", @http=#<Net::HTTP s3-ap-southeast-1.amazonaws.com:80 open=false>>

I have a bucket which is based on "Singapore Region" and for that endpoint i.e. server is: s3-ap-southeast-1.amazonaws.com So when I try to access it using this command -

我有一个基于“新加坡地区”的存储桶,对于该端点,即服务器是:s3-ap-southeast-1.amazonaws.com所以当我尝试使用此命令访问它时 -

AWS::S3::Service.buckets

it fetches all buckets in my account correctly -

它正确地获取我帐户中的所有存储桶 -

=> [#<AWS::S3::Bucket:0x8d291fc @attributes={"name"=>"bucket1", "creation_date"=>2011-06-28 10:08:58 UTC}, @object_cache=[]>,
#<AWS::S3::Bucket:0x8d291c0 @attributes={"name"=>"bucket2", "creation_date"=>2011-07-04 07:15:21 UTC}, @object_cache=[]>,
#<AWS::S3::Bucket:0x8d29184 @attributes={"name"=>"bucket3", "creation_date"=>2011-07-04 07:39:21 UTC}, @object_cache=[]>]

where as bucket1 belongs to Singapore Region and other 2 to US Region. So, when I do this -

其中bucket1属于新加坡地区,其他2属于美国地区。所以,当我这样做时 -

AWS::S3::Bucket.find("bucket1")

it shows me this error:

它告诉我这个错误:

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/surya/.rvm/gems/ruby-1.9.2-p180/gems/aws-s3-0.6.2/lib/aws/s3/error.rb:38:in `raise'
    from /home/surya/.rvm/gems/ruby-1.9.2-p180/gems/aws-s3-0.6.2/lib/aws/s3/base.rb:72:in `request'
    from /home/surya/.rvm/gems/ruby-1.9.2-p180/gems/aws-s3-0.6.2/lib/aws/s3/base.rb:88:in `get'
    from /home/surya/.rvm/gems/ruby-1.9.2-p180/gems/aws-s3-0.6.2/lib/aws/s3/bucket.rb:102:in `find'
    from /home/surya/.rvm/gems/ruby-1.9.2-p180/gems/aws-s3-0.6.2/lib/aws/s3/bucket.rb:145:in `objects'
    from /home/surya/.rvm/gems/ruby-1.9.2-p180/gems/aws-s3-0.6.2/lib/aws/s3/bucket.rb:313:in `reload!'
    from /home/surya/.rvm/gems/ruby-1.9.2-p180/gems/aws-s3-0.6.2/lib/aws/s3/bucket.rb:242:in `objects'
    from /home/surya/.rvm/gems/ruby-1.9.2-p180/gems/aws-s3-0.6.2/lib/aws/s3/bucket.rb:253:in `each'
    from (irb):5
    from /home/surya/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `<main>'

I don't understand the reason why this is happening cause yesterday same thing was working well. Any guess?? am I missing something here??

我不明白为什么会发生这种情况,因为昨天同样的事情运作良好。任何猜测?我在这里遗漏了什么?

4 个解决方案

#1


37  

Before you connect, try using

在连接之前,请尝试使用

AWS::S3::DEFAULT_HOST.replace "s3-ap-southeast-1.amazonaws.com"

Another thing you can do (although this isn't really a good solution) is to access the bucket with the array index

您可以做的另一件事(虽然这不是一个很好的解决方案)是使用数组索引访问存储桶

AWS::S3::Bucket.list[0]

#2


7  

If anyone is getting the issue where you are trying to do different regions for different platforms, you can setup your config like this:

如果有人在尝试为不同平台执行不同区域的问题,您可以像下面这样设置配置:

AWS.config({
    :region => 'us-west-2',
    :access_key_id => ENV["AWS_ACCESS_KEY_ID"],
    :secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"],
    :s3 => { :region => 'us-east-1' }
})

#3


2  

Here I ran into this problem too. Since I live in Brazil I tried creating a sao paulo bucket, after I deleted it and used a US Standart bucket everything panned out well.

在这里我也遇到了这个问题。由于我住在巴西,我尝​​试创建一个圣保罗桶,在我删除它并使用美国Standart桶后,一切都很好。

#4


0  

aws region must be set to us-standard to access S3 buckets.

必须将aws区域设置为us-standard才能访问S3存储桶。

In case of Linux command line, run : export AWS_DEFAULT_REGION="us-standard".

如果是Linux命令行,请运行:export AWS_DEFAULT_REGION =“us-standard”。

#1


37  

Before you connect, try using

在连接之前,请尝试使用

AWS::S3::DEFAULT_HOST.replace "s3-ap-southeast-1.amazonaws.com"

Another thing you can do (although this isn't really a good solution) is to access the bucket with the array index

您可以做的另一件事(虽然这不是一个很好的解决方案)是使用数组索引访问存储桶

AWS::S3::Bucket.list[0]

#2


7  

If anyone is getting the issue where you are trying to do different regions for different platforms, you can setup your config like this:

如果有人在尝试为不同平台执行不同区域的问题,您可以像下面这样设置配置:

AWS.config({
    :region => 'us-west-2',
    :access_key_id => ENV["AWS_ACCESS_KEY_ID"],
    :secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"],
    :s3 => { :region => 'us-east-1' }
})

#3


2  

Here I ran into this problem too. Since I live in Brazil I tried creating a sao paulo bucket, after I deleted it and used a US Standart bucket everything panned out well.

在这里我也遇到了这个问题。由于我住在巴西,我尝​​试创建一个圣保罗桶,在我删除它并使用美国Standart桶后,一切都很好。

#4


0  

aws region must be set to us-standard to access S3 buckets.

必须将aws区域设置为us-standard才能访问S3存储桶。

In case of Linux command line, run : export AWS_DEFAULT_REGION="us-standard".

如果是Linux命令行,请运行:export AWS_DEFAULT_REGION =“us-standard”。