How to upload a file to S3 from static webpage using API Gateway and Lambda
Hello Abhishek
How to upload a file to S3 from static webpage using API Gateway and Lambda
I am new to aws and trying to create simple webpage to upload file in S3 and maintain metadata in DynamoDB. I am able to create record in DynamoDB but not able to load file in S3 from my webpage. I get the following error,
"No such file or directory: ‘C:fakepath2018_pirl_replacement_notes.pdf’: OSError Traceback (most recent call last): File "/var/task/lambda_function.py", line 33, in lambda_handler s3.upload_file……."
I created index.html to create the web form which allows user to enter metadata and select the file to upload. It triggers lambda function where I want to store file in S3 bucket and metadata in DynamoDB.
This is how I am passing the File through webpage,
Can you let me know what I am missing or doing wrong?
Thanks
Hello Abhishek
This is my index.html page
Hello Abhishek
File:
2 Answers
Scott Pletcher
Hi Abhiskek,
I’m kind of confused on the parts and pieces you’re using but I think you’re going to need a few more components. You can upload directly to S3 using Javascript. If you strip ALL the build-in security out, you can do it. But I’m not sure where you’re expecting the Lambda function to come into play? Lambda runs on AWS and doesn’t have access to your local file system to take in a file. You could trigger a Lambda function using an S3 event such that when you upload to S3, the metadata could be extracted by the Lambda function and stored in Dynamo.
–Scott
Maks Khomutskyi
Hi,
In addition to Scott’s answer I will recommend you to check https://fineuploader.com/ . They have github with examples how you can upload to S3 with JS.
This is my index.html page
File: