I am trying to generate a pre-signed URL through boto3 however I get the following error.
The request signature we calculated does not match the signature you provided. Check your key and signing method.
It is strange since I can successfully generate a pre-signed url using the CLI. I have checked that the credentials are all correct.
boto3==1.24.76
import boto3
bucket_name = "xxx"
object_name = "xxx"
iam_access_id = "xxx"
iam_secret_key = "xxx"
s3_client = boto3.client(
"s3", aws_access_key_id=iam_access_id, aws_secret_access_key=iam_secret_key, region_name="eu-west-2"
)
p_url = s3_client.generate_presigned_url(
ClientMethod="get_object",
Params={"Bucket": bucket_name, "Key": object_name},
ExpiresIn=1800,
)
Running on the CLI:
aws s3 presign "s3://xxx" --expires-in 1800
To add to the mystery python successfully creates a presigned URL for files in an old bucket that I have. I tried creating a copy of the old bucket but presigned URL is still incorrect.