Help with Uploading Photos to S3 via Lambda and API Gateway
Asked by
splice_mode
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?
Answers
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.
Reply to this answer
Add your answer
Answers are reviewed before publication.
__version_control: 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.