Overview

AWS serverless solution to extract document attachements from e-mails sent to SES mailbox. The solution relies on integration of following AWS services: SES + S3 + Lambda + EventBridge + CloudWatch.

How it works?

Solution walkthrough:

  1. User sends an e-mail with attachments to SES Email Retrieval endpoint (receiving mailbox)
  2. SES Receipt Rule saves messages as EML files to S3 bucket in the incoming/ folder
  3. SES Receipt Rule invokes the Lambda function and passes metadata about EML file in context
  4. Lambda function loads the EML file from S3 bucket, extracts document attachments (selected content type), and saves them back to S3 bucket in the attachments/ folder.
  5. Lambda execution logs are streamed to a dedicated CloudWatch Log Group
  6. EventBridge custom Bus is configured as Lambda Destination to collect events emitted on Lambda function's successful and failed executions
  7. EventBridge Rule target is configured to stream the events to a dedicated CloudWAtch Log Group
  8. CloudWatch Dashboard uses CloudWatch Log Insights to query for execution and destination logs to show number of successfull or failed Lambda function executions, as well as number of extracted document attachments from the EML files.

How to make it fancy?

EventBridge Bus receives events from Lambda Destinations for successfull and failed executions of Lambda function. You can create an extra Event Rule to catch only the successful executions.

Make sure to input the $.detail.documents (JSON Path) to the Event Rule Target. This is to pass to the target service only part of the event: output of the Lambda function. You can then pass it to any service suported as Event Rule Target for further processing, for example: Step Functions workflow.

AWS CDK App:

Lambda Function:

Built With

Share this project:

Updates