1

各バケットの下に数百万のファイルがある S3 サーバーがあります。バケットからファイルをダウンロードしたいが、特定の条件を満たすファイルのみをダウンロードしたい。すべてのバケットを取得してから、ファイルを繰り返し処理しながら特定の条件をチェックするよりも良い方法はありますか? ここに見られるように:

import os
# Import the SDK
import boto
from boto.s3.connection import OrdinaryCallingFormat

LOCAL_PATH = 'W:/RD/Fancy/s3_opportunities/'

bucket_name = '/recording'#/sampledResponseLogger'

# connect to the bucket
print 'Connecting...'
conn = boto.connect_s3(calling_format=OrdinaryCallingFormat()) #conn = boto.connect_s3()

print 'Getting bucket...'
bucket = conn.get_bucket(bucket_name)

print 'Going through the list of files...' 
bucket_list = bucket.list()

for l in bucket_list:

    keyString = str(l.key)

    # SOME CONDITION
    if('2015-08' in keyString):

        # check if file exists locally, if not: download it
        filename=LOCAL_PATH+keyString[56:]
        if not os.path.exists(filename):

            print 'Downloading file: ' + keyString + '...'

            # Download the object that the key represents
            l.get_contents_to_filename(filename)
4

1 に答える 1