A serverless AWS document-processing pipeline that accepts documents through an API, stores them in S3, processes them asynchronously with SQS and Lambda, extracts text, scans for keywords, and sends notifications through SNS.
The entire infrastructure is managed with Terraform.
- A user uploads a document through the API.
- API Gateway sends the request to the
UploadProcessorLambda. UploadProcessordecodes the Base64 file and stores it in S3.- S3 sends an event to the SQS processing queue.
- SQS triggers the
DocumentParserLambda. DocumentParserretrieves the document from S3.- The parser extracts the document text and scans for keywords.
- Processing results and errors are logged in CloudWatch.
- When keywords are detected, SNS sends an email notification.
- If processing fails, SQS retries the message.
- After the maximum number of retries, the message is moved to the DLQ.
- The
ErrorHandlerLambda processes failed messages from the DLQ and sends an alert.
- API Gateway — Receives document upload requests.
- Lambda — Handles uploads, document processing, and failed messages.
- S3 — Stores uploaded documents.
- SQS — Decouples document uploads from processing and provides retries.
- SQS DLQ — Stores messages that repeatedly fail processing.
- SNS — Sends email notifications.
- CloudWatch — Provides logs, metrics, and alarms.
- IAM — Controls permissions between AWS services.
- DOCX
PDF text extraction is currently implemented in the document parser.
The parser currently scans documents for:
urgent
fraud
invoice
contract
- AWS account
- AWS CLI configured
- Terraform
- Python 3.12+
Build the DocumentParser Lambda package:
./build.shterraform init
terraform plan
terraform applyAfter deployment, Terraform outputs the API URL, S3 bucket, SQS queues, and CloudWatch log groups needed for testing.
Testing instructions are available in the test file in the the root folder
