Hi, when I used aws credential block to access S3 ...
# ask-community
m
Hi, when I used aws credential block to access S3 via boto3, I have this error
boto3.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.
k
Hi @Miller Jiang what version of prefect-aws are you using?
m
prefect-aws 0.2.3
w
Is this problem solved? I got the similar error by using aws credential block. If there's anything else, my task was just check the object's key. Here is my flow code.
Copy code
import 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()
I registered the access and secret access key from read-only IAM account. Could this be related to this issue?