Recently I had a requirement to create a workflow starting from an email. Think of it like this, We receive an email with an Excel Report attachment in a fixed format and we need to automatically parse it and store it in the DB once received.

The below diagram shows the data flow.

None
  1. An email address was created in AWS SES https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-set-up.html
  2. An Email receipt rule was created to store the email data in S3 https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-receipt-rules.html
  3. S3 event was configured to invoke a lambda function written in Java
  4. Lambda function will pick the email message from s3 and do the following
  • Parse the email using javax.mail package
  • Parse the attachment using the Apache POI package and extract data
  • Extracted data is stored in RDS using a JDBC connection

Notes

  • The above functions can be broken into multiple lambda functions for better maintainability
  • Instead of the S3 event, SES can directly invoke a lambda function. That is what is shown in dashed line D.
  • If an acknowledgment need to be sent Lambda can invoke S3 again to trigger an email. In my case that is not a requirement.