Error parsing the X-Amz-Credential parameter

0

Hi there,

I'm trying to upload a large file via a pre-signed URL that is generated by a Lambda function on an API call.

Here's the code that I am currently using. (https://sookocheff.com/post/api/uploading-large-payloads-through-api-gateway/)

import uuid
import os
import boto3


def lambda_handler(event, context):
    # Get the service client.
    s3 = boto3.client('s3', region_name="af-south-1")

    # Generate a random S3 key name
    upload_key = uuid.uuid4().hex+".zip"

    # Generate the presigned URL for put requests
    presigned_url = s3.generate_presigned_url(
        ClientMethod='put_object',
        Params={
            'Bucket': os.environ["CLIENT_BUCKET"],
            'Key': upload_key
        }
    )

    # Return the presigned URL
    return {
        "upload_url": presigned_url
    }

The cURL commands that I run are as follows:

curl -i --request POST "<API-ENDPOINT>"

(This works)

Then I run

curl --request PUT --upload-file ./A_B_C.zip "<PRESIGNED-URL>"

But this returns:

<?xml version="1.0" encoding="UTF-8"?>

<Error><Code>AuthorizationQueryParametersError</Code><Message>Error parsing the X-Amz-Credential parameter; the region 'af-south-1' is wrong; expecting 'us-east-1'</Message><Region>us-east-1</Region><RequestId>G08721G7TVQ1XXVY</RequestId><HostId>tWmM+fSqNwWvpVP2ywko9Qnkc1G1WbCkT0U1L9pqfO3MJXnEt3wy6FKQrUAMjAQ+Y/lpqKabtm8=</HostId></Error>

NOTE: The bucket that I'm trying to reach is in af-south-1

What am I doing wrong here?

gefragt vor einem Jahr2957 Aufrufe
1 Antwort
0

Since the bucket name is unique, you don't need to specify the region at all. Try without it. If not working, refer to these other solutions: https://stackoverflow.com/questions/49522014/imagefield-with-django-storages-leads-to-error-parsing-the-x-amz-credential-pa

I have working result with my lambda in eu-west-1 and the bucket in us-east-1 with this:


import uuid
import os
import boto3


def lambda_handler(event, context):
    # Get the service client.
    s3 = boto3.client('s3')

    # Generate a random S3 key name
    upload_key = uuid.uuid4().hex

    # Generate the presigned URL for put requests
    presigned_url = s3.generate_presigned_url(
        ClientMethod='put_object',
        Params={
            'Bucket': 'test-abaschen-todelete',
            'Key': upload_key,
            'ContentType': 'application/zip'
        },
        HttpMethod='PUT'
    )

    # Return the presigned URL
    return {
        "upload_url": presigned_url
    }
profile pictureAWS
ab
beantwortet vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen