Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Boto获取s3存储桶位置_Python_Amazon Web Services_Boto - Fatal编程技术网

Python Boto获取s3存储桶位置

Python Boto获取s3存储桶位置,python,amazon-web-services,boto,Python,Amazon Web Services,Boto,是否可以使用boto API获取s3中的存储桶位置 我说的是AWS API中的这个函数- 提前感谢。您可以调用get\u location()方法: 对于boto3,您可以使用get_bucket_location方法,该方法将返回以下内容之一(自2019年11月起): “EU”;“EU-west-1”;“us-west-1”;“us-west-2”;“ap-south-1”;“ap-Southwest-1”;“ap-Southwest-2”;“ap-north-1”;“sa-east-1”;“

是否可以使用boto API获取s3中的存储桶位置

我说的是AWS API中的这个函数-


提前感谢。

您可以调用get\u location()方法:


对于boto3,您可以使用get_bucket_location方法,该方法将返回以下内容之一(自2019年11月起):

“EU”;“EU-west-1”;“us-west-1”;“us-west-2”;“ap-south-1”;“ap-Southwest-1”;“ap-Southwest-2”;“ap-north-1”;“sa-east-1”;“cn-north-1”;“EU-central-1”

示例方法如下所示:

def get_location(client, bucket_name):
    response = client.get_bucket_location(Bucket=bucket_name)
    return response['LocationConstraint']

请参阅。

对于不同的桶,此方法有两种不同的行为:1。它只返回空字符串2。它返回403:boto.exception.S3ResponseError:S3ResponseError:403禁止确保您的IAM用户/角色具有调用GetBucketLocation API的权限。这是对全局S3服务的API调用,而不仅仅是一个特定的bucket<代码>{“Version”:“2012-10-17”,“Statement”:[{“Effect”:“Allow”,“Action”:[“s3:GetBucketLocation”],“Resource”:“arn:aws:s3:::::*”}boto使用签名类型v2,默认情况下,它会导致403出现问题吗?我添加了s3:GetBucketLocation,但仍然收到403。您将得到一个空字符串(或LocationConstraint=None with boto3)适用于美国标准。如果您没有针对特定bucket调用s3:GetBucketLocation的权限,您将看到403(是所有bucket,还是一些?)如果bucket\u location:在第4行,那么后面的代码有什么意义?如果您可以在第2行获取bucket,在第3行获取bucket的位置,为什么要调用
conn.get\u bucket(bucket\u name)
再次返回?如果返回“无”意味着什么?
None
返回将表示存储桶不存在,或者您没有查询存储桶位置所需的权限。我需要查看更多的响应才能确定。谢谢@eatsfood,刚刚找到我在这篇文章中查找的内容。
def get_location(client, bucket_name):
    response = client.get_bucket_location(Bucket=bucket_name)
    return response['LocationConstraint']