使用AWS CLI将带有子文件夹和文件的文件夹从服务器复制到S3

时间:2019-06-03 14:27:48

标签: python-3.x amazon-web-services amazon-s3 boto3 aws-cli

我有一个包含一堆子文件夹和文件的文件夹,这些文件夹和文件是我从服务器上获取并分配给变量的。我想使用boto3将这些数据上传到具有相同文件夹结构的S3存储桶。 文件夹结构:

└── main_folder
   ├── folder
    │   ├── folder
    │   │   ├── folder
    │   │   │   └── a.json
    │   │   ├── folder
    │   │   │   ├── folder
    │   │   │   │   └── b.json
    │   │   │   ├── folder
    │   │   │   │   └── c.json
    │   │   │   └── folder
    │   │   │       └── d.json
    │   │   └── folder
    │   │       └── e.json
    │   ├── folder
    │   │   └── f.json
    │   └── folder
    │       └── i.json
        try:
            for dirname in utils['BucketData']:
                cmd = ['aws', 's3', 'sync', dirname, 's3://{}/{}/'.format(input_bucket_name, folder_name)]
                sp = subprocess.run(cmd)
        except Exception as e:
            logger.debug('Command error: {}'.format(e))

变量详细信息:

utils['BucketData'] = It is data(mentioned is folder structure) which fetched from server. It is in dict form
dirname = fetching directories and copying to s3 location
input_bucket_name = Bucket name where my folder is located.
folder_name = where I want copy the data.

我跑步时得到

The user-provided path 'directory name' does not exist.

如何复制与S3中分配给变量的文件夹结构相同的确切数据? 怎么了?

1 个答案:

答案 0 :(得分:0)

(首先作为评论,我不确定这是否是解决问题的方法。)

您可以使用

StringLength

也许您需要添加Validation Attribute