Miller Jiang
01/05/2023, 11:09 PMboto3.exceptions.S3UploadFailedError: Failed to upload. An error occurred (SignatureDoesNotMatch) when calling the PutObject operation: The request signature we calculated does not match the signature you provided. Check your key and signing method.
Kalise Richmond
01/06/2023, 8:00 PMMiller Jiang
01/07/2023, 12:10 AMwonsun
02/24/2023, 6:57 AMimport boto3
from prefect import flow
from prefect_aws import AwsCredentials
def get_bytes(t):
def inner(bytes_amount):
t.update(bytes_amount)
return inner
@flow
def download_from_bucket():
my_block = AwsCredentials.load('aidataops')
s3 = boto3.resource('s3',
aws_access_key_id=my_block.aws_access_key_id,
aws_secret_access_key=my_block.aws_secret_access_key)
bucket = s3.Bucket('test_bucket')
#print(bucket.name)
obj_list = []
for obj in bucket.objects.all(): #error point!
obj_list.append(obj.key)
#print(len(obj_list))
df_raw = pd.DataFrame(obj_list, columns=['obj_source'])
df_final = df_raw[df_raw['obj_source'].str.contains('result')].reset_index(drop=True)
temp_src_path = df_final['obj_source'][0]
temp_dest_path = 'local_save_path'
config = boto3.s3.transfer.TransferConfig(multipart_threshold=1024**2, max_concurrency=1)
file_size = s3.Object(bucket.name, temp_src_path).content_length
file_name = os.path.basename(temp_src_path)
destination_path = os.path.abspath(temp_dest_path+'/'+file_name)
print('>>> download file : (S3 storage) ' + src_path + ' -> (Local) ' + destination_path)
with tqdm(total=file_size, unit='B', unit_scale=True, desc=src_path, ascii=True) as t:
bucket.download_file(temp_src_path, temp_dest_path, Config=config, Callback=get_bytes(t))
if __name__=='__main__':
download_from_bucket()
wonsun
02/24/2023, 7:29 AM