AWS Builder Center

Title: Extracting Text from Documents with Amazon Textract

Discover how Amazon Textract uses AI to extract text, tables, and form data from documents through a practical AWS hands-on project.

IT Student | Full-Stack Developer | AI/ML & Cloud Enthusiast
Businesses handle large volumes of documents, including invoices, application forms, receipts, and reports. Manually extracting information from these files can be time-consuming.
Amazon Textract helps automate this process by using machine learning to detect and extract printed text, handwriting, tables, and form fields from documents.

Five important AWS concepts

  1. Amazon Textract: Extract text and structured information from documents.
  1. Amazon S3: Store documents before processing them.
  1. AWS Lambda: Automate document processing workflows.
  1. Amazon SNS: Send notifications when processing is complete.
  1. Amazon CloudWatch: Monitor processing activity and troubleshoot errors.

Hands-on AWS Example: Extract Text from an Image

Objective: Upload a document image to S3 and use Amazon Textract to extract its text.
Step 1: Create an S3 bucket
  • Open the AWS Management Console.
  • Navigate to Amazon S3.
  • Create a bucket named  document-processing-demo .
  • Keep Block Public Access enabled.
  • Upload a sample JPG or PNG containing printed text.
Step 2: Configure IAM permissions
Create or use an IAM role that allows the application to:
  • Read the uploaded object from S3.
  • Call the required Amazon Textract operation.
Step 3: Extract text using Python
Install Boto3 in your Python environment if needed:
pip install boto3
Use the following code:
import boto3

textract = boto3.client("textract", region_name="ap-south-1")

response = textract.detect_document_text(
Document={
"S3Object": {
"Bucket": "document-processing-demo",
"Name": "sample.png"
}
}
)

for item in response["Blocks"]:
if item["BlockType"] == "LINE":
print(item["Text"])
Step 4: Run the program
  • Configure AWS credentials securely using an IAM role or AWS profile.
  • Replace the bucket and file names with your actual values.
  • Execute the Python script.
Step 5: Verify the output
If the uploaded image contains:
 Welcome to AWS Cloud Computing 
The extracted output should include:
Welcome to AWS Cloud Computing

What You Learn

This exercise introduces document processing, OCR, AWS SDK integration, S3 connectivity, IAM permissions, and AI-powered automation.
Important: The synchronous  DetectDocumentText  operation supports JPEG, PNG, PDF, and TIFF documents within its documented size and page limits. For multi-page asynchronous processing, explore  StartDocumentTextDetection . Review AWS pricing and delete test resources after completing the exercise.
AI-powered document processing can reduce repetitive manual work and help businesses build smarter workflows.
What would you automate using Amazon Textract: invoice processing, resume screening, or document verification?
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article