尝试使用CopyObject修饰/重新处理S3对象

时间:2017-06-26 20:59:29

标签: python-2.7 amazon-web-services amazon-s3 aws-lambda

我正在尝试使用copy_object来修饰或替换s3中的相同文件,我收到以下错误,我不确定我的代码中缺少什么。

我收到以下错误:

An error occurred (NoSuchKey) when calling the CopyObject operation: The specified key does not exist.: NoSuchKey
Traceback (most recent call last):
File "/var/task/S3_Reprocessing.py", line 109, in lambda_handler
s3.copy_object(Bucket=bucketName, Key=Object_to_reprocess, CopySource=copy_source)
File "/var/runtime/botocore/client.py", line 253, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/var/runtime/botocore/client.py", line 557, in _make_api_call
raise error_class(parsed_response, operation_name)
NoSuchKey: An error occurred (NoSuchKey) when calling the CopyObject operation: The specified key does not exist. 

附上我的参考资料

for filePath in downloadedFilePath:
    print filePath
    csv_file = filePath
    with open(csv_file, 'rb') as f:
        reader = csv.reader(f, delimiter=':')
        mydict = dict((rows[0], rows[1]) for rows in reader)
        data = json.dumps(mydict)
        data2 = json.loads(data, object_hook=JSONObject)
        bucketName = data2.bucketName
        print "%s : is the target bucket" % bucketName
        Reprocess_files = data2.Reprocess_files
        files = Reprocess_files.split(",")
        for f in files:
            print "%s : is the file to reprocess" % f
            Object_to_reprocess = f.strip()

            # Driving Tgt_folder from Object_to_reprocess
            SplitArray = Object_to_reprocess.split("/")
            lenofSplitArray = len(SplitArray)
            filename = SplitArray[lenofSplitArray - 1]
            Tgt_folder = string.replace(Object_to_reprocess, filename, ' ')

            src_object = bucketName + Object_to_reprocess

            # s3.Object(bucketName, Tgt_folder).copy_from(CopySource=Object_to_reprocess, ServerSideEncryption='AES256')

            copy_source = {'Bucket': bucketName, 'Key': Object_to_reprocess}

            s3.copy_object(Bucket=bucketName, Key=Object_to_reprocess, CopySource=copy_source) 

0 个答案:

没有答案