Can't use AWS Credentials of prefect blocks

I’m trying to create a flow that automatically downloads some files in an S3 bucket.
So i registered the AWS Credentials block that name ‘test_block’.
However, if the block is entered as a required argument of the boto3 client in flow, the following error occurs.

@flow
def check_conn():
    my_block = AwsCredentials.load('testblock') 
    s3 = boto3.client('s3', 
                aws_access_key_id = my_block.aws_access_key_id, 
                aws_secret_key = my_block.aws_secret_access_key)
    reponse = s3.list_buckets()
    print('Existing buckets: ')
    for bucket in response['Buckets']:
        print(f'    {bucket["Name"]}')

if __name__=='__main__':
    check_conn()
    

And they returns below error ;

botocore.exceptions.ClientError: An error occurred (SignatureDoesNotMatch) when calling the ListBuckets operation: The request signature we calculated does not match the signature you provided. Check your key and signing method.

How can i solve this?
When i wrote ‘access key’ and ‘secret access key’ by directly in the flow, there’s no problem.

1 Like