How to full-text search an Amazon S3 bucket
Codemia Knowledge Hub ·
You can't full-text search an S3 bucket with S3 alone. S3 is object storage: it lists objects by key and prefix, but it does not index what is inside them. The working approach is to extract text from each object, index that text in a search engine such as Amazon OpenSearch Service, and send your queries to the index.
What S3 does and does not do
S3 stores objects and their metadata, and retrieves them efficiently when you already know the key, prefix or surrounding workflow. It does not tokenize text, build inverted indexes, rank results, or pull content out of PDFs, Word documents or HTML files. So full-text search over a bucket takes three steps:
- Extract text from the objects.
- Index that text in a system built for search.
- Query the index, not S3.
The usual AWS architecture
- S3 stores the original files.
- An event trigger detects new or changed objects.
- A processor extracts text and metadata.
- Amazon OpenSearch Service holds the searchable index.
S3 stays the durable source of truth for the files, and the search engine handles ranking and retrieval.
Indexing uploaded text files with Lambda
For plain text files, a Lambda function can read each new object and index it in OpenSearch. A simplified example:
Extracting text from PDFs and Office files
For PDFs or Office documents, add a text extraction step before indexing. Without it, those files look "missing" from search results. Common options:
- AWS Lambda with a library that parses PDF or Office formats
- AWS Textract for scanned or image-heavy documents
- A containerized batch job for large or complex documents
Index the extracted text together with useful metadata such as object key, upload time, tags, customer ID or document type. Indexing only filenames or object keys is not full-text search.
Why Athena and S3 Select are not enough
- Amazon Athena runs SQL over structured data stored in S3, such as JSON, CSV or Parquet.
- S3 Select retrieves subsets of structured object content.
Neither is a relevance-ranked document search engine. For logs, tables or newline-delimited JSON, Athena may be enough. For "search every word inside uploaded documents," using Athena gives a poor experience; use a search index.
Querying the index
Once the documents are in OpenSearch, a search is a simple query against the indexed content:
Keeping the index in sync with the bucket
A production setup needs more than the initial indexing:
- Re-index documents when objects are replaced.
- Delete index entries when S3 objects are deleted, or the index drifts away from the bucket.
- Store ACL-related metadata if access control matters.
- Normalize text, language and file encodings.
- Monitor indexing failures and dead-letter events.
For large buckets, run a one-time backfill job so the index also covers objects that existed before the trigger was set up.
Related reading
- How do you get kubectl to log in to an AWS EKS cluster?
- How do you install modules within sagemaker training jobs?
- How do you locally load model.tar.gz file from Sagemaker?
- How do you look at console.log output of the amazon lambda function
- How do you make an S3 object public via the aws Java SDK?
- How do you pass Authorization header through API Gateway to HTTP endpoint?
- How do you pass custom environment variable on Amazon Elastic Beanstalk AWS EBS?
- How do you put up a maintenance page for AWS when your instances are behind an ELB?
Course lessons on this
System design interview problems on this topic
- Design Dropbox: solution and walkthrough
- Design a Global Content Distribution Network: solution and walkthrough
- Design a Serverless Architecture Framework: solution and walkthrough
- Design Youtube or Netflix: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.