Help with Uploading Photos to S3 via Lambda and API Gateway

0
0
Asked By SkyDancer42 On

Hey everyone! I'm new to AWS and I'm having trouble uploading photos to S3 from my React/NodeJS application. I've set up everything using AWS Amplify and it's deployed successfully. I've created a Lambda function to manage the uploads and set up the API Gateway to expose it. I also created an S3 bucket with the necessary permissions.

Initially, I encountered some CORS issues but I think I've resolved them by adding the right headers. Here's what happens when I try to upload a photo: the first request is an OPTIONS call, then I send a PUSH call to get the upload URL, and finally a PUT call to save the photo. Unfortunately, during the last step, it returns a 500 error indicating an undefined endpoint. Any tips on what might be causing this and how I can fix it?

1 Answer

Answered By TechGuru88 On

That OPTIONS call is just the browser checking for CORS approval. If your Lambda doesn’t return the right CORS headers, especially for the PUT request, S3 can block it, even if the URL looks good.

PhotoUploader99 -

The POST gets the correct upload URL for the lambda, but the PUT call seems broken and points to an undefined endpoint. This is puzzling. The error logs aren’t providing details either—only a status code 500 showing that the lambda can’t write to S3.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.