'sending emails through lambda at different time

I am trying to build a newsletter service. In the newsletter service, a user can decide at what time he/she should receive the email daily. I am trying to achieve this using aws resources and wanted to check if this is possible, I have gone through multiple services: SNS, SES, event bridges but looks like I am missing something as it doesn't appear to be possible.

Here is the usecase in detail:

I have a lambda function, let's call it sendEmailLambda which sends an email to different users, depending on the given user id passed to lambda function as an input parameter. I want to trigger this lambda function at different times, and the time is decided by the preferred time of a user. I store the userids and the preferred time in the dynamo db. For example: let's say I have two users user1 and user2 and their preferred time is 9 am and 1 pm respectively. Both of these details are stored in dynamodb. The sendEmailLambda should trigger at 9 am and send the email to user1 and likewise it should again trigger at 1 pm and send the email to user2.

I am looking for help on how to do so?



Solution 1:[1]

Write a lambda (lambda function A) function that sends an email via SES.

Write another lambda function (lambda function B) that creates/updates an EventBridge rule that has lambda function A as a target. Configure a text constant for the event which includes the email address of the user.

Trigger lambda function B every time an item is created in DynamoDB via DynamoDB stream (every time an item is either created or updated on DynamoDB, the rule associated with the user will be created/updated).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Paolo