Home > Enterprise >  AWS triggering email
AWS triggering email

Time:11-29

I am using lambda function to send customized email, which is connected to DynamoDB stream. The logic is that, whomever wants to send an email, submits the metadata to email DynamoDB, which is then captured by the lambda. Lambda then checks the metadata and finds the template it should send, fills the necessary holes with the parameters given in the metadata and sends it to its recipient. The DynamoDB submitter in this case is the back-end services. They will submit email metadata whenever an email needs to be sent after an execution of an endpoint.

I don't want this logic to lie in the endpoint function logic directly, since it will add an asynchronous operation to the execution (submitting to email DynamoDB). But rather I am looking for a way to either synchronously submitting of email without expecting a result back (but it should be submitted 100%), or a way to auto-capture the result of the endpoints, and if the results indicate a case to send an email, a parallel service should be run without interrupting the request. For the second idea I was thinking maybe there is something that can be done with the help of API Gateway. Maybe something like, result is returned to API Gateway, based on the condition, Gateway returned the result to the client, and triggered email sender in the back.

The above 2 are the ways I can think of to make email submission to DynamoDB in an unblocking way. Are these doable? If they are not what can I do to make it happen, or can I at all?

All the app data lies in Postgres database, and endpoints are connected to it.

CodePudding user response:

You can use SQS.

Dynamo Stream -> Lambda -> SQS -> Email Lambda

The stream will emit an event, another lambda will push it into an SQS, then your original lambda can subscribe to the SQS. This way you have 100% guaranteed delivery in an async flow.

You can configure retries and if a particular email can't be sent it can go to a dead letter queue where you can examine them

  • Related