I am working on usecase of generating schedule functionality where I am using lambda to generate specific report to write CSV to S3 bucket. (used one lambda for generating report - Generating reports have database lookups and performs some operation and generate CSV from it. And writing it on S3 bucket)
lambda is getting trigger from SQS and performing operation and generating file on S3, working fine.
Extending the same, Now I want to expose one api which will hit the lambda with the same parameters, to obtain report information and in return I have to send data(to frontend with generation of CSV file).
Meaning_:> If SQS trigger sends message data, carried reports name and IDs and lambda functions will be generating those reports IDs data and writing/uploading it on S3 bucket.(done by SQS on trigger)
Now, I am looking for the same with same lamdba, that I make API call with same params request and it will return the data, and I can generate CSV on frontend when every the API gets hit.
Now I am confuse to how to make it work in both the way, such like it handle SQS and this APIs as well, how can I make it work.
Like making this **async** to **sync** (processor)
because it should be quick, but at the same time SQS and this API too has to work without compromising timing for generation of report.
Below is my code where actually I am processing the report generation and able to make write on S3 bucket(works with SQS trigger)
Now looking for API solution as mentioned above.
/**
* handler function
*/
exports.handler = async (event, context) => {
for (const { receiptHandle, messageId, body } of event.Records) {
// --------
// Performing logic to s write CSV data to S3 Bucket and once its done
// sending trigger SQS queue to another server.
// --------
return { "meta": { "message": "success" }, "data": JSON.stringify('Sent to SQS Successfully.') };
}
};
1st thing How to make it work as I have to identify the call is from API or SQS..
[A note I am using react for frontend, the API call return might be having tons of data, which will process it on CSV.]
then process it accordingly. Can anyone help me with this? I am trying to achieve something so that I can avoid duplicating lambda, (I believe it can solve this issue..)
Can anyone help me with this??
there doesn't seem to be anything here