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!

답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠