Turn scanned documents, forms, and tables into structured data your app can use, going well beyond plain text scanning. Stop seven in the AWS Hidden Gems series.
Most AWS learning stops after EC2, S3, IAM, and Lambda. But AWS has over two hundred services, and many of the most useful ones rarely appear in tutorials.
AWS Hidden Gems covers those underrated services you shouldn't ignore. Each article picks one, then explains why it exists, what it does, where it fits, and how to set it up from the console. Know the four basics above and you can follow along. Everything else gets explained as it comes up.
Plenty of important data is trapped in documents: invoices, forms, receipts, IDs, contracts. Textract reads those documents and pulls out not just the words, but the structure. It knows which value belongs to which field on a form and how a table's rows and columns line up.
Getting data out of documents has always been painful. Typing it in by hand is slow and error prone. Plain OCR, which stands for optical character recognition and means turning an image of text into machine readable text, gives you the words but throws away the layout. You get a wall of text with no idea that "Total: 42.00" means the total field holds 42.00, or which numbers sat in which table cell.
Textract is OCR plus document understanding. AWS trained models that recognize forms and tables, so instead of raw text you get field and value pairs and structured tables. That is the difference between reading a document and actually using it.
Textract is a managed document analysis service. It reads text from images and PDFs, and it understands common document structures.
It can pull out:
An accounts team receives hundreds of supplier invoices as PDFs every month. Someone opens each one and copies the invoice number, date, and total into their system by hand.
It is slow, and typos cause real accounting errors. They want the key fields pulled out of each invoice automatically and dropped into their database.
Textract does exactly this. Its invoice analysis returns the fields they care about from each PDF, so the data flows in without manual typing, and the mistakes that came with it disappear.
Documents land in S3. A common pipeline: an upload triggers a Lambda function, the function calls Textract, and the structured results are stored in DynamoDB or passed on for more processing. For long PDFs, Textract sends a notification through SNS when the background job is done. Extracted text often flows next into Comprehend, the AWS text analysis service, to find meaning in it.
flowchart LR
A[Document uploaded] --> B[S3 bucket]
B -->|Upload event| C[Lambda function]
C -->|Analyze document| D[Textract]
D -->|Fields, tables, text| C
C -->|Store structured data| E[DynamoDB]
Textract is the reader. Storage and triggers use familiar services, and Textract turns the document into data.
For a single image or short document, you send it to Textract and get structured results back right away: text, form pairs, and tables. For a multi page PDF in S3, you start a job, Textract processes it in the background, and it notifies you through SNS when the results are ready to fetch. You choose what to extract by asking for features, such as forms and tables, or by using the invoice or identity document analysis for those specific cases.
flowchart TD
A[Document] --> B{Size?}
B -->|Single image| C[Call Textract, get results instantly]
B -->|Multi page PDF| D[Start a job]
D --> E[Textract processes in background]
E --> F[SNS notifies you]
F --> G[Fetch structured results]
The Textract console lets you try extraction on your own document before writing code.
This reads a document in S3 and prints its text, line by line.
import boto3
textract = boto3.client("textract")
response = textract.detect_document_text(
Document={
"S3Object": {"Bucket": "my-docs-bucket", "Name": "invoice.png"}
}
)
for block in response["Blocks"]:
if block["BlockType"] == "LINE":
print(block["Text"])
For form fields and tables, call analyze_document instead, with FeatureTypes of ["FORMS", "TABLES"]. Its output links keys to their values through relationships, which is fiddly to walk by hand, so most people use the Textract Response Parser library (trp) to read the pairs and tables directly.
| Item | Detail |
|---|---|
| Text detection | Per page, cheapest option, plain text only |
| Forms or tables | Per page, higher rate, for structured data |
| Queries | Per page, for asking specific questions |
| Invoice or ID analysis | Per page, for those document types |
| Free tier | Pages per month for the first 3 months, across text and analysis |
AWS AI Services
├── Textract text and structured data from documents
├── Rekognition understanding of images and video
├── Comprehend meaning and sentiment in text
├── Transcribe speech to text
├── Translate language translation
└── Polly text to speech
Textract and Rekognition both read images, but for different goals. Rekognition, from earlier in this series, understands the scene in a photo. Textract understands the document on the page. They often pair with Comprehend, which analyzes the text once it is extracted.
Textract reads documents the way you need software to: not just the words, but which value goes with which field and how tables are laid out. It replaces manual data entry from invoices, forms, and scans with a single API call. Next time data is stuck inside a PDF, you know how to get it out as structured data.
You are on stop seven of AWS Hidden Gems.
Questions, corrections, or want to talk through where this fits in your own project? Reach me at khantanseer43@gmail.com.