r/awslambda • u/dafcode • Mar 03 '24
How do I pass data from frontend to the Lambda function?
Hey folks, I have a Next.js app, where users select a PDF file and click on “Upload”. Then the PDF file gets saved to an S3 bucket. This triggers a Lambda function, which does the necessary processing.
I also need to pass some data (available at the frontend) to the Lambda function. (Currently I have hard-coded this data in the Lambda function). What options do I have?
Note that I don’t want to use function URL because the processing of the PDF file is a time-consuming task, and I don’t want the user to wait on the page for the result. Currently, once the PDF file is uploaded, I just show a message to the user saying that the processing has started.
2
Upvotes
3
u/burgonies Mar 03 '24
Remove the lambda S3 trigger and have that function trigger off SQS or SNS (depending on how parallel you want things processed)
Create a lightweight function with an HTTP trigger that you can pass some JSON with your metadata and the path to the relevant PDF that you uploaded to S3. Dump that JSON into that SQS or SNS and return 200.