0

I am using

boto3==1.17.57

I have read AWS S3 - How to fix 'The request signature we calculated does not match the signature' error?

But I am not sure why I am still getting

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

when I try to perform PUT operation.

My code snippet is pretty straightforward.

import requests
import boto3
from botocore.client import ClientError

s3 = boto3.resource('s3')

bucket_name = 'cloud-storage-1'
file_name = 'car.jpg'



########
# BUCKET
########
try:
    s3.meta.client.head_bucket(Bucket=bucket_name)
except ClientError as e:
    print(str(e))
    print("Try to create bucket for the first time")

    s3.create_bucket(
        Bucket=bucket_name,
        CreateBucketConfiguration={
            'LocationConstraint': 'eu-central-1'
        }
    )



##################
# GET FILE CONTENT
##################
with open(file_name, 'rb') as object_file:
    body = object_file.read()
object_file.close()



###############
# PRESIGNED URL
###############
s3_client = boto3.client('s3')

url = s3_client.generate_presigned_url(
    ClientMethod='put_object',
    Params={
        'Bucket': bucket_name, 
        'Key': file_name
    },
    ExpiresIn=3600
)

print(url)



#####
# PUT
#####
response = requests.put(url, data=body)

print(response.content)

I can confirm the ~/.aws/credentials is correct, as I can see the bucket being created with no issue.

Bucket created without issue

enter image description here

~/.aws/credentials

[default]
aws_access_key_id=XXX
aws_secret_access_key=YYY
region=eu-central-1

Does anyone has any idea why it is so?

Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
  • What about time? Maybe your system clock is too much different then that of AWS? – Marcin Apr 25 '21 at 07:48
  • I check the system clock of my Docker system. It looks fine. (I run the Python script in Docker environment). It is weird that this problem just happen randomly. If I tend to clean up entire S3 files and buckets, it will help to resolve the problem sometimes. Or, if I run the script in next morning, it helps too. Not sure why :-( – Cheok Yan Cheng Apr 26 '21 at 18:55

0 Answers0