Ruby-on-rails AWS S3:您尝试访问的存储桶必须使用指定的端点进行寻址
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25027462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AWS S3: The bucket you are attempting to access must be addressed using the specified endpoint
提问by user3575214
I am trying to delete uploaded image files with the AWS-SDK-Core Ruby Gem.
我正在尝试使用 AWS-SDK-Core Ruby Gem 删除上传的图像文件。
I have the following code:
我有以下代码:
require 'aws-sdk-core'
def pull_picture(picture)
Aws.config = {
:access_key_id => ENV["AWS_ACCESS_KEY_ID"],
:secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"],
:region => 'us-west-2'
}
s3 = Aws::S3::Client.new
test = s3.get_object(
:bucket => ENV["AWS_S3_BUCKET"],
:key => picture.image_url.split('/')[-2],
)
end
However, I am getting the following error:
但是,我收到以下错误:
The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
您尝试访问的存储桶必须使用指定的端点进行寻址。请将所有未来的请求发送到此端点。
I know the region is correct because if I change it to us-east-1, the following error shows up:
我知道该区域是正确的,因为如果我将其更改为us-east-1,则会出现以下错误:
The specified key does not exist.
指定的键不存在。
What am I doing wrong here?
我在这里做错了什么?
回答by Marcus Walser
It seems likely that this bucket was created in a different region, IE not us-west-2. That's the only time I've seen "The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint."
这个存储桶似乎是在不同的区域创建的,IE 而不是 us-west-2。那是我唯一一次看到“您尝试访问的存储桶必须使用指定的端点进行寻址。请将以后的所有请求发送到此端点。”
US Standard is
us-east-1
美国标准是
us-east-1
回答by Jay Q.
Check your bucket location in the console, then use this as reference to which endpoint to use: http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
在控制台中检查您的存储桶位置,然后将其用作要使用的端点的参考:http: //docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
回答by prasun
I was facing a similar error because the bucket was in region us-west-2and the URL pattern had bucketname in the path. Once, I changed the URL pattern to have bucketname as URL subdomain to grab the files and it worked.
我遇到了类似的错误,因为存储桶在区域中us-west-2,并且 URL 模式在路径中有存储桶名称。有一次,我将 URL 模式更改为将 bucketname 作为 URL 子域来抓取文件,并且它工作正常。
For eg previous URL was
例如之前的 URL 是
https://s3.amazonaws.com/bucketname/filePath/filename
Then I replaced it as
然后我将其替换为
https://bucketname.s3.amazonaws.com/filePath/filename
回答by Duncan
For many S3 API packages (I recently had this problem the npm s3 package) you can run into issues where the region is assumed to be US Standard, and lookup by name will require you to explicitly define the region if you choose to host a bucket outside of that region.
对于许多 S3 API 包(我最近遇到了npm s3 包这个问题),您可能会遇到假设区域为美国标准的问题,如果您选择托管存储桶,按名称查找将要求您明确定义区域在那个区域之外。
回答by Rathan
During the creation of S3Client you can specify the endpoint mapping to a particular region. If default of s3.amazonaws.comthen bucket will be created in us-east-1which is North Virginia.
在创建 S3Client 期间,您可以指定端点映射到特定区域。如果默认,s3.amazonaws.com则将在us-east-1其中创建北弗吉尼亚州的存储桶。
More details on S3 endpoints and regions in AWS docs: http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region.
AWS 文档中有关 S3 端点和区域的更多详细信息:http: //docs.aws.amazon.com/general/latest/gr/rande.html#s3_region。
So, always make sure about the endpoint/region while creating the S3Client and access S3 resouces using the same client in the same region.
因此,在创建 S3Client 并使用同一区域中的相同客户端访问 S3 资源时,请始终确保端点/区域。
If the bucket is created from AWS S3 Console, then check the region from the console for that bucket then create a S3 Client in that region using the endpoint details mentioned in the above link.
如果存储桶是从 AWS S3 控制台创建的,则从控制台检查该存储桶的区域,然后使用上述链接中提到的终端节点详细信息在该区域中创建 S3 客户端。
回答by Peter Grainger
None of the above answers fixed my issue.
以上答案都没有解决我的问题。
The above answers are probably more likely the cause of your problem but my issue was that I was using the wrong bucket name. It was a valid bucket name, it just wasn't my bucket.
上述答案可能更可能是您的问题的原因,但我的问题是我使用了错误的存储桶名称。这是一个有效的存储桶名称,只是不是我的存储桶。
The bucket I was pointing to was in a different region that my lambda function so check your bucket name!
我指向的存储桶与我的 lambda 函数位于不同的区域,因此请检查您的存储桶名称!
回答by dansek
I live in uk was keep on trying for 'us-west-2'region. So redirected to 'eu-west-2'. The correct region for S3 is 'eu-west-2'
我住在英国一直在努力争取“us-west-2”地区。所以重定向到'eu-west-2'。S3 的正确区域是“eu-west-2”
回答by CamHart
This occurred for me when I had a source ip constraint on the policy being used by the user (access key / secret key) to create the s3 bucket. My IP was accurate--but for some reason it wouldn't work and gave this error.
当我对用户(访问密钥/密钥)用于创建 s3 存储桶的策略有源 ip 约束时,就会发生这种情况。我的 IP 是准确的——但由于某种原因它不起作用并给出了这个错误。
回答by Vikram Kodag
After a long search, I found a working solution. The issue was because of the wrong region-code.
经过长时间的搜索,我找到了一个可行的解决方案。问题是因为错误region-code。
below is the list of region-codes, set the appropriate one and your issue will be solved.
下面是区域代码列表,设置适当的区域代码,您的问题将得到解决。
Code Name
US East (Ohio) us-east-2
US East (N. Virginia) us-east-1
US West (N. California) us-west-1
US West (Oregon) us-west-2
Asia Pacific (Hong Kong) ap-east-1
Asia Pacific (Mumbai) ap-south-1
Asia Pacific (Osaka-Local) ap-northeast-3
Asia Pacific (Seoul) ap-northeast-2
Asia Pacific (Singapore) ap-southeast-1
Asia Pacific (Sydney) ap-southeast-2
Asia Pacific (Tokyo) ap-northeast-1
Canada (Central) ca-central-1
Europe (Frankfurt) eu-central-1
Europe (Ireland) eu-west-1
Europe (London) eu-west-2
Europe (Paris) eu-west-3
Europe (Stockholm) eu-north-1
Middle East (Bahrain) me-south-1
South America (S?o Paulo) sa-east-1
You can find your region-code on click of bucket name right corner.
您可以通过单击右侧的存储桶名称找到您的区域代码。
For mode details Click
模式详情请点击
回答by kokociel
I encountered this issue when using a different AWS profile. I saw the error when I?was using an account with admin permissions, so the possibility of permissions issues seemed unlikely.
我在使用不同的 AWS 配置文件时遇到了这个问题。我在使用具有管理员权限的帐户时看到了错误,因此权限问题的可能性似乎不大。
It's really a pet peeve of mine that AWS is so prone to issuing error messages that have such little correlation with the required actions, from a user perspective.
从用户的角度来看,AWS 很容易发出与所需操作几乎没有关联的错误消息,这真是让我感到恼火。


