Issue
We use MongoDB atlas, a cloud MongoDB database for our DB and NodeJS in the backend. I have to run a cron job at 2 AM every day which fetches the data from some third-party API and updates some collection in the DB. The client wants us to use AWS, preferably Lamda. Our System is run on an EC2 instance. Any leads ?? What would be the most efficient solution? It worked fine with 'node-cron' in my local but they want lamdas preferably AWS.
Solution
You can do that by attaching the cron trigger event on AWS lambda. You can use the same code that you are running on local.
It will be easy for you to use SAM cli for lambda, it will help you deploy and test your lambda easily.
What would be the most efficient solution ?
I believe there won't be any challenge for efficiency. There will be difference in billing, if you are only running this code base on the EC2 instance you need to start the EC2 instance to trigger the cron-job. However, AWS lambda will be only charged when trigger run the code for the cron-job. There won't be any major difference, but I believe lambda could be better for this job.
So, I recommend you to use AWS lambda for this job.
You should check this link which tells how many different ways we can trigger cron-job in AWS.
Answered By - Apoorva Chikara Answer Checked By - Marilyn (WPSolving Volunteer)