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 個回答
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!

已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南