admin管理员组

文章数量:1194969

def get_presigned_url(self, expiration=3600):
    s3_client = boto3.client(
        's3',
        aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
        aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY,
        region_name=settings.AWS_REGION_NAME,
        config=Config(signature_version='s3v4')
    )
    from urllib.parse import quote

    key = f"media/{quote(self.file.name)}"
    
    presigned_url = s3_client.generate_presigned_url(
       'put_object',
        Params={'Bucket': settings.BUCKET_NAME, 'Key': key},
        ExpiresIn=expiration,
    )
    return presigned_url

I am currently generating the presigned_url, and when I try to access it, I receive

SignatureDoesNotMatch The request signature we calculated does not match the signature you provided. Check your key and signing method.

In order to check that my ACCESS_KEY and SECRET_ACCESS_KEY, I tried to login to AWS CLI, and then I've done this:

Entered CLI, and wrote the exact ACCESS_KEY and SECRET_ACCESS_KEY that I am using in the code.

echo "test content" > test-file.txt
aws s3 cp test-file.txt s3://bucket_name/test-file.txt --profile my-profile

and it was successful (I was able to see it in the bucket):

upload: ./test-file.txt to s3://bucket_name/test-file.txt

I added access to the bucket:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::bucket_name/*"
        }
    ]
}

For the user, I gave the full access to S3, just in case.

After all these attempts, I still receive :

SignatureDoesNotMatch The request signature we calculated does not match the signature you provided. Check your key and signing method.

本文标签: amazon s3AWSS3 The request signature we calculated does not match the signature you providedStack Overflow