2017-08-02 12 views
0

Helllo、私は非常に大きいS3バケットからすべてのファイルをダウンロードしようとしていますPythonのBoto3:エラーは、AWS S3

からファイルをダウンロードしようとします。私は、このことから

client = boto3.client('s3', 
aws_access_key_id=tempCredentials.credentials.access_key, 
aws_secret_access_key = tempCredentials.credentials.secret_key,         
aws_session_token=tempCredentials.credentials.session_token) 

:私はこのようなS3に接続していますよう

# This is going to go through and fill in the dictionary with keys 
from the buckets as specified above 
paginator = client.get_paginator("list_objects") 
page_iterator = paginator.paginate(Bucket=bucket["Name"]) 
l = 0 
# We are going to have an list that will hold all the keys 
key_list = [] 
for i in page_iterator: 
    c = i["Contents"] 
    for j in c: 
      key_list.append(j["Key"]) 
    for j in key_list: 
     download(bucket["Name"], j, "/Users/ahussain/Desktop/S3_Scrubber/" + file_name_helper(j), client) 

場合には、私のダウンロード機能:

def download (bucket_name, key, path, client): 
    key_name = key 
    print("Dowloading %s..." % str(key)) 
    client.download_file(bucket_name, key, path) 
    print("Download of %s complete!" % str(key)) 
    return key_name 

何が起こることは私が通過するということですバケットはうまくいっていて、適切な量の鍵をダウンロードしますが、しばらくするとプログラムの鍵ダウンロードが停止し、このエラーが表示されます。

botocore.exceptions.ClientError: An error occurred (400) when calling the HeadObject operation: Bad Request 

私はこのS3にアクセスするためにMFAを使用しているのでセッションが切れていると思われますが、わかりません。誰もこのエラーに遭遇したことはありますか?

+0

クライアントを構築するときに、バケットがある領域を指定できますか? 'client = boto3.client( 's3'、region_name = 'us-west-1'、....' – helloV

答えて

0

一時的な資格情報は、最大1時間有効です。

The duration, which specifies how long the temporary security credentials are valid. The minimum is 15 minutes (900 seconds) and the maximum (and the default) is 1 hour (3600 seconds). You need to pass this value only if you want the temporary credentials to expire before 1 hour.

オープンバグ(https://github.com/boto/boto3/issues/443boto3によると、長時間実行される操作のための一時的な信任状のリフレッシュをサポートしていません:IAM documentationから。

スクリプトが〜1時間後にエラーを表示する場合は、その理由が考えられます。

関連する問題