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 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则