Can't upload file to S3 due to 500 error on OPTIONS request

0

Hello,

I am trying to upload a file via a generated pre-signed URL to my s3 bucket. When I initiate the upload the browser starts with a OPTIONS request to the s3 url which returns a 500 error. If I try to upload a file to the pre-signed URL via postman I get a timeout.

This works with my bucket in eu-north-1, but I recently created a bucket in eu-west-2 with the same permissions and CORS rules as my bucket in eu-north-1 but I can't get it to work.

More info:

  • User has the AmazonS3FullAccess policy attached to it
  • CORS rule in bucket:
[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "GET",
            "PUT",
            "POST",
            "DELETE"
        ],
        "AllowedOrigins": [
            "*"
        ],
        "ExposeHeaders": []
    }
]
  • Generation of presigned url with python:
location = f"users/{user_id}/{filename}"
expirationInMinutes = 60

response = s3_client.generate_presigned_url(
  "put_object",
  Params={"Bucket": {S3_BUCKET}, "Key": location},
  ExpiresIn=expirationInMinutes * 60,
)
  • Response from s3 presigned url when OPTIONS REQUEST is sent:
<?xml version="1.0" encoding="UTF-8"?>
<Error>
    <Code>InternalError</Code>
    <Message>We encountered an internal error. Please try again.</Message>
    <RequestId>{REDACTED}</RequestId>
    <HostId>{REDACTED}</HostId>
</Error>
asked 5 months ago320 views
1 Answer
0

The issue you're experiencing with the 500 error on OPTIONS requests for your S3 bucket in eu-west-2 could be due to a few potential factors:

  1. Temporary S3 service issues: Sometimes, S3 can experience temporary internal errors in specific regions. This could explain why it works in eu-north-1 but not in eu-west-2.

  2. CORS configuration: Although you've set up CORS rules, ensure that the CORS configuration is properly applied to the new bucket in eu-west-2. Sometimes, CORS changes can take a little time to propagate.

  3. Bucket policy: Double-check that the bucket policy in eu-west-2 allows the necessary actions, especially for cross-origin requests.

  4. Presigned URL generation: Ensure that the S3 client used to generate the presigned URL is configured for the correct region (eu-west-2).

To troubleshoot:

  1. Wait a short while and try again, in case it's a temporary S3 service issue.

  2. Verify that the CORS configuration is correctly applied to the eu-west-2 bucket.

  3. Check the bucket policy to ensure it's not inadvertently blocking the request.

  4. Confirm that your S3 client is configured for the eu-west-2 region when generating the presigned URL.

  5. Try generating a presigned URL with a longer expiration time to rule out timing issues.

  6. Use AWS CloudTrail or S3 server access logging to get more detailed information about the requests and any errors.

If the issue persists after these steps, it may be worth contacting AWS support for further assistance, as they can investigate potential service-side issues specific to the eu-west-2 region.
Sources
Troubleshooting HTTP 5xx errors from Amazon S3 | AWS re:Post
Community | Secure File Uploads to S3 Using AWS Lambda
Generating a presigned URL to upload an object to an S3 on Outposts bucket - Amazon S3 on Outposts

profile picture
answered 5 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions