I need to upload a file using a web form to AWS and then trigger a function to import it into a Postgres DB. I have the file import to a DB working locally using Java, but need it to work in the cloud It needs a file upload with some settings (such as which table to import into) to be passed through a Java function which imports it to the Postgres DB I can upload files to an EC2 instance with php, but then need to trigger a lambda function on that file. My research suggests S3 buckets are perhaps a better solution? Looking for some pointers to which services could be best suited
2 Answers
You can use AWS SDK in your convenient language to invoke Lambda.
Please refer this documentation

- 1,424
- 1
- 13
- 29
There are two main steps in your scenario:
Step 1: Upload a file to Amazon S3
It is simple to create an HTML form that uploads data directly to an Amazon S3 bucket.
However, it is typically unwise to allow anyone on the Internet to use the form, since they might upload any number and type of files. Typically, you will want your back-end to confirm that they are entitled to upload the file. Your back-end can then Upload objects using presigned URLs - Amazon Simple Storage Service, which authorize the user to perform the upload.
For some examples in various coding languages, see:
- Direct uploads to AWS S3 from the browser (crazy performance boost)
- File Uploads Directly to S3 From the Browser
- Amazon S3 direct file upload from client browser - private key disclosure
- Uploading to Amazon S3 directly from a web or mobile application | AWS Compute Blog
Step 2: Load the data into the database
When the object is created in the Amazon S3 bucket, you can configure S3 to trigger an AWS Lambda function, which can be written in the programming language of your choice.
The Bucket and Filename (Key) of the object will be passed into the Lambda function via the event
parameter. The Lambda function can then:
- Read the object from S3
- Connect to the database
- Insert the data into the desired table
It is your job to code this functionality but you will find many examples on the Internet.

- 241,921
- 22
- 380
- 470
-
Thanks. I already have part 2 coded, except it's reading locally and not from S3 which is a straightforward change. I appreciate part 1 - that's just what I needed! Thank you – James Farrow Jul 06 '21 at 02:30
-
My solution was an upload to S3 bucket from webform which triggered the lambda function to ingress the file into the PostGres database. I used custom metadata tags to instruct the lambda on what functions to run on the file and the table name to import into – James Farrow Aug 25 '21 at 02:40
-
@JamesFarrow Glad to hear you got it working! You are welcome to add your own Answer to detail what you did, so future readers can benefit from your experience. – John Rotenstein Aug 25 '21 at 03:19