我注意到似乎没有从AWS管理控制台下载整个s3桶的选项。

有什么简单的方法可以把所有东西都装进我的桶里吗?我正在考虑使根文件夹公共,使用wget抓取它,然后再次使它私有,但我不知道是否有更简单的方法。


当前回答

如果你只有文件在那里(没有子目录),一个快速的解决方案是选择所有的文件(点击第一个,Shift+点击最后一个),然后按Enter或右键单击并选择打开。对于大多数数据文件,这将直接下载到您的计算机。

其他回答

您有许多选项可以做到这一点,但最好的是使用AWS CLI。

下面是一篇简介:

Download and install AWS CLI in your machine: Install the AWS CLI using the MSI Installer (Windows). Install the AWS CLI using the Bundled Installer for Linux, OS X, or Unix. Configure AWS CLI: Make sure you input valid access and secret keys, which you received when you created the account. Sync the S3 bucket using: aws s3 sync s3://yourbucket /local/path In the above command, replace the following fields: yourbucket >> your S3 bucket that you want to download. /local/path >> path in your local system where you want to download all the files.

除了关于aws s3同步的建议外,我还建议查看s5cmd。

根据我的经验,我发现对于多次下载或大规模下载,这比AWS CLI要快得多。

S5cmd支持通配符,这样可以工作:

S5cmd cp s3://桶名/* ./文件夹

对于Windows, S3浏览器是我发现的最简单的方法。这是一款优秀的软件,而且非商业用途是免费的。

使用boto3下载具有特定前缀的桶中的所有对象

import boto3

s3 = boto3.client('s3', region_name='us-east-1', 
                     aws_access_key_id=AWS_KEY_ID, 
                     aws_secret_access_key=AWS_SECRET)

def get_all_s3_keys(bucket,prefix):
    keys = []

    kwargs = {'Bucket': bucket,Prefix=prefix}
    while True:
        resp = s3.list_objects_v2(**kwargs)
        for obj in resp['Contents']:
             keys.append(obj['Key'])

        try:
            kwargs['ContinuationToken'] = resp['NextContinuationToken']
        except KeyError:
            break

        return keys

def download_file(file_name, bucket,key):
    file=s3.download_file(
    Filename=file_name,
    Bucket=bucket,
    Key=key)
    return file

bucket="gid-folder"
prefix="test_"
keys=get_all_s3_keys(bucket,prefix):

for key in keys:
     download_file(key, bucket,key)
   
 

我已经为S3做了一些开发,我还没有找到一个简单的方法来下载整个存储桶。

如果您想用Java编写代码,那么jets3t库很容易用于创建存储桶列表并遍历该列表以下载它们。

首先,从AWS管理咨询器获取一个公共私钥集,这样您就可以创建一个S3service对象:

AWSCredentials awsCredentials = new AWSCredentials(YourAccessKey, YourAwsSecretKey);
s3Service = new RestS3Service(awsCredentials);

然后,获取bucket对象的数组:

S3Object[] objects = s3Service.listObjects(YourBucketNameString);

最后,遍历该数组,每次下载一个对象:

S3Object obj = s3Service.getObject(bucket, fileName);
            file = obj.getDataInputStream();

我把连接代码放在线程安全的单例中。由于显而易见的原因,省略了必要的try/catch语法。

如果你更愿意用Python编写代码,你可以使用Boto。

在查看BucketExplorer之后,“下载整个桶”可能会满足你的需要。