Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

python - Using boto for AWS S3 Buckets for Signature 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()

and I got the following:

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()

How can I fix it properly?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...