I am facing issue like "SignatureDoesNotMatch" when I try to hit "generate_presigned_url" from Postman

0

**Error ----------------------------------------------------------------------------------------------: **

<?xml version="1.0" encoding="UTF-8"?> <Error> <Code>SignatureDoesNotMatch</Code> <Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message> <StringToSign>PUT

**Code in Python----------------------------------------------------------------------------------------------: ** import botocore import boto3 import datetime from botocore.exceptions import ClientError import json

s3_file="test6.jpg" def lambda_handler(event, context): # TODO implement print("Step 1") try: s3 = boto3.client('s3') url = s3.generate_presigned_url( ClientMethod='get_object', Params={ 'Bucket': 's3_Bucket', 'Key': s3_file }, ExpiresIn=36000000 )

    result = {'status': 'success', 'data': {'url': url, 'key':s3_file}}
    response = {
        'statusCode': 200,
        'body': json.dumps(result),
        'headers': {
            'Content-Type': 'application/json'
        }
    }
    
except ClientError as e:
    print(f'Error generating presigned URL: {e}')
    return None

return response
1 réponse
0

This is unintuitive but happend to me in the past. Most probably you are missing permissions to the Lambda that creates the SignedUrl... I know... AWS should throw an error when we are creating it, not when we are consuming it... but this fixed my problem then...

In the template, go to the Lambda that creates the SignedUrl and in the properties, add the following Policies:

  • AWSLambdaVPCAccesExecutionRole
  • AWSLambdaBasicExecutionRole
  • S3CrudPolicy: BucketName: my-bucket-unique-name

I hope it helps!

répondu il y a un an

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions