question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

generate_presigned_url no longer works, gives: SignatureDoesNotMatch

See original GitHub issue
import boto3,requests,os

def get_session():
    access_key = os.getenv('JAR_LAMBDA_ACCESS_KEY')
    secret_key = os.getenv('JAR_LAMBDA_SECRET_KEY')
    if None in [access_key, secret_key]:
        raise Exception('KEYs not set')
    session = boto3.Session(aws_access_key_id=access_key, aws_secret_access_key=secret_key, region_name='eu-central-1')
    return session

def print_url():
    key = 'mykey'
    bucket = 'mybucket'
    try:
        session = get_session()
        s3 = session.client('s3', config=boto3.session.Config(signature_version='s3v4'), region_name='eu-central-1')
        url = s3.generate_presigned_url(ClientMethod='get_object', Params={'Bucket': bucket, 'Key': key}, ExpiresIn=3600)
        print(url)
        resp = requests.get(url)
        print(resp)
    except Exception as e:
        print(e)

The browser gives a 403 and:

<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>
The request signature we calculated does not match the signature you provided. Check your key and signing method.
</Message>
...

Signing with:

aws s3 presign s3://mybuket/mykey --expires 1800 --profile presigner

works perectly. The presigner profile has the same keys as the python code above.

Versions: Python 3.7.0 (had the same issue with 3.6.*) boto3-1.7.70 botocore-1.10.70 s3transfer-0.1.13

Please also read this: https://stackoverflow.com/questions/50213740/aws-s3-presigned-urls-with-boto3-signature-mismatch

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:20 (2 by maintainers)

github_iconTop GitHub Comments

32reactions
hamx0rcommented, Oct 31, 2018

@imperio59 's answer helped, but I also needed to set signature_version='s3v4':

s3 = boto3.client('s3', aws_access_key_id={YOUR ACCESS KEY}, aws_secret_access_key={YOUR SECRET ACCESS},
                  config=Config(s3={'addressing_style': 'path'}, signature_version='s3v4'))

boto3 1.9.28 (1.9.34 is latest available) botocore 1.12.28 (1.12.34 is latest available) python 3.6.4 (MacOS)

21reactions
sejascommented, Apr 23, 2019

Thanks @Trogious ! We had the same issue SignatureDoesNotMatch uploading an image from our React Native APP.

I fixed it passing the signature_version='s3v4' and the region_name

s3 = session.client('s3',
                    config=boto3.session.Config(signature_version='s3v4'),
                    region_name='eu-central-1'
)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Boto3 generate_presigned_url, SignatureDoesNotMatch error
I know this is a bit late to answer, but I solved my problem by following the method as specified in this GitHub...
Read more >
The request signature we calculated does not match ... - Reddit
SignatureDoesNotMatch - The request signature we calculated does not match the signature you provided. Check your key and signing method.
Read more >
S3 Signature Does Not Match Error When Using A Pre Signed ...
So I made my pre signed url using the AWS SDK: $cmd = $s3Client->getCommand('PutObject', array( 'Bucket' => $bucket, 'Key' => $key )); $request ......
Read more >
R2 storage: unable to upload using pre-signed url, getting ...
I am using boto3 to generate pre-signed URL. ... Posting to the URL is not working the way it's described in the boto3...
Read more >
Access files from AWS S3 using pre-signed URLs in Python
A pre-signed URL gives you **temporary **access to the object identified in the URL, ... The URL throws a signature does not match...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found