**Building a Simplified Intelligent Document Processing (IDP) System on AWS**
In this article, I walk through the design and implementation of a simplified cloud-based Intelligent Document Processing (IDP) system using Amazon Web Services (AWS). The solution demonstrates how email-based document intake, automated classification, and Personally Identifiable Information (PII) extraction can be orchestrated in a secure, scalable, and production-aware manner.
—
### High-Level Workflow
The system is designed to process email attachments containing identity documents, such as passports, driving licenses, and bank statements. It extracts text, classifies document types, and identifies key PII using a combination of serverless and AI services.
The core workflow is as follows:
1. **Email Trigger:** Emails with a specific label (e.g., “DocumentProcessing”) containing image attachments are monitored.
2. **Attachment Validation:** Each email is checked for exactly one valid image attachment.
3. **Text Extraction:** Images are sent to Amazon Textract for Optical Character Recognition (OCR).
4. **Classification & PII Extraction:** Extracted text is analyzed by Amazon Bedrock (Claude Sonnet) to classify the document and extract fields like name, date of birth, and address.
5. **Result Storage & Notification:** Results are stored in S3 and can be forwarded securely.
—
### AWS Services Used
– **IAM:** Manages permissions across services.
– **EventBridge:** Schedules the automation workflow.
– **Step Functions:** Orchestrates Lambda invocations and error handling.
– **Lambda:** Executes compute logic at each stage.
– **S3:** Stores raw images, Textract output, and final results.
– **Secrets Manager:** Secures OAuth credentials and tokens.
– **Textract:** Performs OCR on document images.
– **Bedrock:** Runs Claude Sonnet for document classification and PII extraction.
—
### Implementation Steps
#### 1. Storing OAuth Credentials Securely
Gmail OAuth credentials (client ID, client secret, and refresh token) are stored in AWS Secrets Manager. This allows Lambdas to authenticate securely when accessing the Gmail API.
#### 2. Setting Up S3 Buckets
Five S3 folders are created:
– **raw/** – for incoming email attachments
– **textract/** – for OCR output
– **results/** – for classification and PII results
– **audit/** – for logs
– **quarantine/** – for unclassified documents
#### 3. Creating Lambda Functions
Three Lambda functions are developed:
– **ingest_email_image**
– Polls Gmail for new labeled emails.
– Validates and stores attachments in the S3 raw folder.
– Skips invalid or duplicate files.
– **extract_text**
– Triggered for each new image in S3.
– Uses Amazon Textract to extract text.
– Saves structured JSON output to the textract folder.
– **classify_and_extract_pii**
– Receives Textract output.
– Uses Amazon Bedrock (Claude Sonnet 4.6) to classify document type and extract PII.
– Writes structured results to the results folder.
#### 4. Step Functions for Orchestration
An AWS Step Function coordinates the workflow:
1. Invoke `ingest_email_image`.
2. For each valid image, invoke `extract_text`.
3. For each Textract result, invoke `classify_and_extract_pii`.
4. Log success or failure.
A visual diagram of the flow is included in the article for clarity.
#### 5. Scheduling with EventBridge
An EventBridge rule triggers the Step Function on a recurring schedule (e.g., weekdays at 11:55 PM). This makes the process fully automated without manual intervention.
—
### Example Outputs
After processing sample images (passport, bank statement, driving licence), the system returns structured JSON:
– **Bank Statement**
– Classification: `bank_statement`
– PII: Name, account number, statement period, address
– **Passport**
– Classification: `passport`
– PII: Full name, date of birth, issuing country, address
– **Driving Licence**
– Classification: `driving_licence`
– PII: Full name, date of birth, address, license number
—
### Frequently Asked Questions (FAQ)
**Q1: Can this system handle PDF documents?**
Yes, with additional processing. Textract supports PDF analysis, and Lambda can preprocess MIME types to route PDFs correctly.
**Q2: How are multiple attachments handled?**
The current example assumes one attachment per email. It can be extended by iterating over all attachments and processing each independently.
**Q3: What about data privacy and security?**
Credentials are stored in Secrets Manager. S3 buckets should be encrypted, and IAM roles follow least-privilege principles. Audit logging is enabled for compliance.
**Q4: Can I use this for real-world production?**
The article outlines a bare-bones version. A production-ready system would need:
– A human-in-the-loop (HIL) interface for verification
– Multi-document and multi-format support
– Automated result delivery (e.g., password-protected PDFs)
– Centralized logging and monitoring
**Q5: Is Amazon Textract always required?**
Not necessarily. For simple, structured images, Bedrock can process raw pixel data directly. Textract is kept in the pipeline for complex or noisy documents.
—
### Conclusion
This article demonstrated how to build a simplified yet functional Intelligent Document Processing system on AWS. By combining serverless functions, AI services, and orchestration tools, it is possible to automate document intake, classification, and PII extraction from email attachments.
While the example uses synthetic images and a streamlined prompt, the architecture provides a solid foundation that can be extended for enterprise-grade document processing. To move toward production, focus on handling multiple formats, adding verification layers, and ensuring comprehensive logging and monitoring.
For complete code, IAM policies, Step Function definitions, and Terraform scripts, refer to the GitHub repository linked in the original article.
If you are looking for support or consulting around data engineering, AI pipelines, or cloud automation, feel free to reach out through the channels mentioned.



