0

I recently created my first AWS web application using elastic beanstalk and the MERN (MongoDB, Express, React, NodeJS) stack and now I need to query my database daily to trigger emails.

Initially I was thinking about just creating a hook in my web service that handles the query+email logic since I already have all the neccessary models/connections in my web service and would just need a batch job once a day to call that web service hook but it would need to send credentials and call it via https.

Alternatively, I could just re-code all of my smtp/database models & connections in a separate batch program to run the query and send the emails.

Which option to you think is better/possible with AWS without using a new standalone EC2 instance? Would AWS Batch or Lambda make better sense? I need something that schedules these db queries+emails at the same time daily.

Sean Merron
  • 442
  • 4
  • 15

2 Answers2

0

As you need to schedule tasks at the same time daily; another option you can consider is to setup a worker environement in which you can deploy your app with a cron.yaml file. All you'll need to do then is to update your security group, granting access to your database by the worker.

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features-managing-env-tiers.html#worker-periodictasks

titili
  • 207
  • 1
  • 6
0

AWS has a rich toolset to solve such requirements.

  1. AWS Lambda can be scheduled to run at definite intervals.
  2. Generate the data (details for email) to be sent as JSON
  3. Push the json into SQS
  4. Use another AWS Lambda to read the SQS to send emails in batches

This solution is scalable, maintainable and cost also will be very less compared to EC2 instances.

Robin Varghese
  • 1,158
  • 10
  • 22