检索斗的对象,不知道斗的地区与AWS的S3 REST API [英] Retrieve bucket's objects without knowing bucket's region with AWS S3 REST API

查看:570
本文介绍了检索斗的对象,不知道斗的地区与AWS的S3 REST API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检索与AWS的S3 REST API水桶的对象(我没有使用SDK),但不幸的是我现在面临以下的问题:我不知道它的区域当我做调用API。

I'm trying to retrieve a bucket's objects with AWS S3 REST API (I'm not using the SDK) but unfortunately I'm facing the following problem : I don't know its region when I do the call to the API.

下面是我做的:

  • 在我建立的请求为https:// [bucketname] .s3.amazonaws.com /
  • 在我使用的是默认的区域设置签名的请求,以美西-1(使用AWS4签名过程)
  • 但是想象一下水桶,我试图让被设定为全区美西-2,AWS是扔我一个错误

因此​​,这里是我的问题:

Therefore here's my question:

有没有什么办法让一个桶的对象列表,而不知道它的区域?或者有没有简单的方法来获取桶的区域?

Is there any way to get a list of the objects of a bucket without knowing its region ? Or is there any simple way to get the region of a bucket ?

信息:我读过有两种风格,叫斗,路径式和虚拟托管式,但每当我将请求发送到的 https://s3.amazonaws.com/ [bucketname]相反,它给了我一个永久重定向错误...

INFO : I've read there are two style to call a bucket, "path-style" and "virtual-hosted-style", but whenever I send the request to "https://s3.amazonaws.com/ [bucketname]" instead it gives me a redirectpermanent error...

谢谢您的回答。

干杯。

推荐答案

AWS V4认证的需要你知道桶的区域,这样可以正确签名的请求。否则:

AWS V4 authentication requires that you know the bucket's region so that you can correctly sign the request. Otherwise:

HTTP/1.1 400 Bad Request

<?xml version="1.0" encoding="UTF-8"?>
<Error>
  <Code>AuthorizationHeaderMalformed</Code>
  <Message>The authorization header is malformed; the region 'us-east-1' is wrong; expecting 'us-west-2'</Message>
  <Region>us-west-2</Region>
  <RequestId>xxxx</RequestId>
  <HostId>xxxx</HostId>
</Error>

V2签名不是特定区域的,所以有previously你可以使用V2要求学习桶的区域一个简单的方法:

V2 signatures were not region-specific, so there was previously a simple way you could learn the bucket's region using a V2 request:

http://docs.aws.amazon.com/AmazonS3/最新/ API / RESTBucketGETlocation.html

不过,美联社$ P $标准杆是一个catch-22与V4,因为你必须知道该桶的区域,然后才能拨打电话,发现桶的区域。

However, there apprears to be a catch-22 with V4, since you have to know the bucket's region before you can make the call to discover the bucket's region.

第一个解决方案,那么,是捕捉&LT;地区&GT; 返回的错误响应,并使用该区域签署的桶将来的请求。很显然,你会想缓存此信息,因为不这样做会降低性能并增加成本。

The first solution, then, is to capture the <Region> returned in the error response and use that region for signing future requests for the bucket. Obviously, you'd want to cache this information, since not doing so would lower performance and increase costs.

另外,还有一种方法可以向美国标区域(美国东部-1)任何桶的位置,在任何地区,使用这种URL格式的

Alternately, there is a way to ask the US-Standard region (us-east-1) about the location of any bucket, in any region, using this URL format only:

https://s3.amazonaws.com/bucket-name?location

网友这一要求与美国东1区,你会得到回应,无论桶恰好是。请注意,如果桶是摆在我们东-1(美国标准)的 LocationConstraint 返回空的。

<?xml version="1.0" encoding="UTF-8"?>
<LocationConstraint xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
  us-west-2
</LocationConstraint>

您不能使用此URL构造的上市实际上在其他地区斗的对象,因为 https://s3.amazonaws.com/ 总是路线的要求,美国标准(美国东部-1),但你可以用它来发现任何桶的区域,因为美国标准有可用的信息。

You cannot use this URL construct for actually listing bucket objects in other regions, since https://s3.amazonaws.com/ always routes your request to US-Standard (us-east-1) but you can use it to discover the region of any bucket, since US-Standard has that information available.

更新/产生额外

在某一点上,S3似乎已经增加了一个新的响应头, X-AMX-斗区:其中的出现的是一个无证除了REST API,和的出现的被添加到许多S3中错误响应,特别是403错误。

At some point, S3 appears to have added a new response header, x-amx-bucket-region: which appears to be an undocumented addition to the REST API, and appears to be added to many S3 error responses, particularly 403 errors.

这似乎是自我纠正一个有用的机制,如果你收到一个错误响应。

This seems like a useful mechanism for self-correction if you receive an error response.

另外,高于约询问所述美国标准区域有关任何桶的位置的任何位置仍然是准确的,并且在同一请求应该工作,如果发送给任何区域S3中的REST端点,不只是美国标准中,由于各区域的信息都知道的所有其他桶的位置,例如:在 https://s3-us-west-2.amazonaws.com/bucket-name?location 将要求美国西-2(俄勒冈州),其中也有同样的资料显示,在全球范围任何桶。这可能需要在某些情况下,询问离你最近的区域。

Also, the information above about interrogating the US-Standard region about the location of any bucket anywhere is still accurate, and the same request should work if sent to any regional S3 REST endpoint, not just US-Standard, since all regions are aware of the location of all other buckets: e.g. https://s3-us-west-2.amazonaws.com/bucket-name?location would ask US-West-2 (Oregon), which also has the same information available, for any bucket globally. It might be desirable in some cases to interrogate your nearest region.

这篇关于检索斗的对象,不知道斗的地区与AWS的S3 REST API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆