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

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ