本文介绍了将 boto 用于签名 V4 的 AWS S3 存储桶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在为法兰克福地区的 S3 存储桶使用 Python-Boto SDK 时遇到问题.根据亚马逊链接,该地区将只支持V4.此文档解释了如何为 Boto SDK 添加 V4 支持.我添加了一个新部分:

I have a problem with using Python-Boto SDK for S3 Buckets for region Frankfurt. According to Amazon link this region will only support V4.This document explains how to add V4 support for Boto SDK.I have added a new section:

if not boto.config.get('s3', 'use-sigv4'):
    boto.config.add_section('s3')
    boto.config.set('s3', 'use-sigv4', 'True')

然后我创建了新连接并获得了所有存储桶:

and then I have created new connection and got all buckets:

connection = S3Connection(accesskey, secretkey, host=S3Connection.DefaultHost)
buckets = connection.get_all_buckets()

它工作正常,但后来我尝试为我的存储桶获取所有密钥:

it works fine, but then I tried to get all keys for my bucket:

for bucket in buckets:
    bucket.get_all_keys()

我得到了以下信息:

S3ResponseError: 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 'eu-central-1'</Message><Region>eu-central-1</Region>

为什么会这样?之后,我连接到该区域并获得了所有需要的数据:

Why did it occur?After that I connected to the region and got all needed data:

region_con = boto.s3.connect_to_region('eu-central-1', aws_access_key_id=accesskey, aws_secret_access_key=secretkey)
bucket = region_con.get_bucket(bucket.name)
bucket.get_all_keys()

我该如何正确修复它?

推荐答案

我在使用 Boto 时遇到了同样的问题.该地区是法兰克福,并在错误地区出现错误.我的解决方案只是指向一个主机(从这个页面获得的 URI http://docs.aws.amazon.com/general/latest/gr/rande.html) 到 's3.eu-central-1.amazonaws.com' 而不是默认值's3.amazonaws.com'

I had the same issue using Boto. The region was Frankfurt and got errors about wrong regions. The solution for me was just to point a host (an URI got from this page http://docs.aws.amazon.com/general/latest/gr/rande.html) to 's3.eu-central-1.amazonaws.com' instead of default 's3.amazonaws.com'

s3 = boto.s3.connect_to_region('eu-central-1',
                               aws_access_key_id=accesskey,
                               aws_secret_access_key=secretkey,
                               host='s3.eu-central-1.amazonaws.com')

这篇关于将 boto 用于签名 V4 的 AWS S3 存储桶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 08:29