AWS.Textract reference
Adapter
Section titled “Adapter”Source:
src/AWS/Textract/Adapter.ts
An Amazon Textract adapter — a container for custom, trained adapter
versions that enhance the pre-trained Queries feature for your specific
documents. The adapter itself is cheap metadata (name, feature types,
auto-update, tags); versions are trained separately with
CreateAdapterVersion against an annotated dataset.
Adapter: Managing Adapters
Section titled “Adapter: Managing Adapters”Create an adapter for the Queries feature
const adapter = yield* AWS.Textract.Adapter("InvoiceAdapter", { featureTypes: ["QUERIES"], description: "Tuned for invoice layouts", autoUpdate: "ENABLED",});Analyze a document with a trained adapter version
const analyzeDocument = yield* AWS.Textract.AnalyzeDocument();const result = yield* analyzeDocument({ Document: { S3Object: { Bucket: bucketName, Name: "invoice.pdf" } }, FeatureTypes: ["QUERIES"], QueriesConfig: { Queries: [{ Text: "What is the invoice total?" }] }, AdaptersConfig: { Adapters: [{ AdapterId: adapter.adapterId, Version: "1" }], },});AnalyzeDocument
Section titled “AnalyzeDocument”Source:
src/AWS/Textract/AnalyzeDocument.ts
Runtime binding for textract:AnalyzeDocument — synchronous analysis of
relationships in a document: forms (key-value pairs), tables, layout,
signatures, and natural-language queries. Pass the document as raw bytes
or as an S3 object reference; the caller needs s3:GetObject on the
bucket for S3 input (bind AWS.S3.GetObject(bucket) alongside).
AnalyzeDocument: Synchronous Analysis
Section titled “AnalyzeDocument: Synchronous Analysis”// initconst analyzeDocument = yield* AWS.Textract.AnalyzeDocument();
// runtimeconst result = yield* analyzeDocument({ Document: { Bytes: documentBytes }, FeatureTypes: ["FORMS", "TABLES"],});const tables = (result.Blocks ?? []).filter((b) => b.BlockType === "TABLE");AnalyzeExpense
Section titled “AnalyzeExpense”Source:
src/AWS/Textract/AnalyzeExpense.ts
Runtime binding for textract:AnalyzeExpense — synchronous analysis of
invoices and receipts, extracting summary fields (vendor, total, dates)
and line-item groups.
AnalyzeExpense: Synchronous Analysis
Section titled “AnalyzeExpense: Synchronous Analysis”// initconst analyzeExpense = yield* AWS.Textract.AnalyzeExpense();
// runtimeconst result = yield* analyzeExpense({ Document: { Bytes: receiptBytes },});const fields = result.ExpenseDocuments?.[0]?.SummaryFields;AnalyzeID
Section titled “AnalyzeID”Source:
src/AWS/Textract/AnalyzeID.ts
Runtime binding for textract:AnalyzeID — synchronous extraction of
identity-document fields (name, date of birth, document number, …) from
images of passports, driver licenses, and other government IDs.
AnalyzeID: Synchronous Analysis
Section titled “AnalyzeID: Synchronous Analysis”// initconst analyzeID = yield* AWS.Textract.AnalyzeID();
// runtimeconst result = yield* analyzeID({ DocumentPages: [{ Bytes: licenseBytes }],});const fields = result.IdentityDocuments?.[0]?.IdentityDocumentFields;CreateAdapterVersion
Section titled “CreateAdapterVersion”Source:
src/AWS/Textract/CreateAdapterVersion.ts
Runtime binding for textract:CreateAdapterVersion — train a new
version of the bound adapter from an annotated dataset manifest in S3
(automated retraining pipelines). The AdapterId is injected
automatically; the caller also needs read access to the manifest and
write access to the output bucket.
CreateAdapterVersion: Managing Adapters
Section titled “CreateAdapterVersion: Managing Adapters”// initconst createAdapterVersion = yield* AWS.Textract.CreateAdapterVersion(adapter);
// runtimeconst { AdapterVersion } = yield* createAdapterVersion({ DatasetConfig: { ManifestS3Object: { Bucket: bucketName, Name: "manifest.jsonl" }, }, OutputConfig: { S3Bucket: bucketName, S3Prefix: "training-output/" },});DeleteAdapterVersion
Section titled “DeleteAdapterVersion”Source:
src/AWS/Textract/DeleteAdapterVersion.ts
Runtime binding for textract:DeleteAdapterVersion — delete a version
of the bound adapter (e.g. retire superseded versions from a retraining
pipeline).
DeleteAdapterVersion: Managing Adapters
Section titled “DeleteAdapterVersion: Managing Adapters”// initconst deleteAdapterVersion = yield* AWS.Textract.DeleteAdapterVersion(adapter);
// runtimeyield* deleteAdapterVersion({ AdapterVersion: "1" });DetectDocumentText
Section titled “DetectDocumentText”Source:
src/AWS/Textract/DetectDocumentText.ts
Runtime binding for textract:DetectDocumentText — synchronous OCR that
detects lines and words of text in a JPEG, PNG, PDF, or TIFF document.
Textract is a pure pay-per-call service with no resource to manage: the
binding takes no arguments and grants the function
textract:DetectDocumentText (the action has no resource-level IAM).
Pass the document as raw bytes (Document.Bytes) or as an S3 object
reference (Document.S3Object) — raw distilled types, no marshalling.
DetectDocumentText: Detecting Document Text
Section titled “DetectDocumentText: Detecting Document Text”// initconst detectDocumentText = yield* AWS.Textract.DetectDocumentText();
// runtimeconst result = yield* detectDocumentText({ Document: { Bytes: documentBytes },});const lines = (result.Blocks ?? []) .filter((block) => block.BlockType === "LINE") .map((block) => block.Text);GetAdapter
Section titled “GetAdapter”Source:
src/AWS/Textract/GetAdapter.ts
Runtime binding for textract:GetAdapter — read the configuration
(name, feature types, auto-update, tags) of the bound adapter at
runtime. The grant is scoped to the adapter’s ARN and the AdapterId
is injected automatically.
GetAdapter: Managing Adapters
Section titled “GetAdapter: Managing Adapters”// initconst getAdapter = yield* AWS.Textract.GetAdapter(adapter);
// runtimeconst result = yield* getAdapter();console.log(result.AdapterName, result.FeatureTypes);GetAdapterVersion
Section titled “GetAdapterVersion”Source:
src/AWS/Textract/GetAdapterVersion.ts
Runtime binding for textract:GetAdapterVersion — read the training
status, dataset configuration, and evaluation metrics of a version of
the bound adapter.
GetAdapterVersion: Managing Adapters
Section titled “GetAdapterVersion: Managing Adapters”// initconst getAdapterVersion = yield* AWS.Textract.GetAdapterVersion(adapter);
// runtimeconst result = yield* getAdapterVersion({ AdapterVersion: "1" });if (result.Status === "ACTIVE") { // ready for AnalyzeDocument AdaptersConfig}GetDocumentAnalysis
Section titled “GetDocumentAnalysis”Source:
src/AWS/Textract/GetDocumentAnalysis.ts
Runtime binding for textract:GetDocumentAnalysis — read the status and
results of an asynchronous document-analysis job started with
StartDocumentAnalysis. Page through large result sets with NextToken.
GetDocumentAnalysis: Asynchronous Document Analysis
Section titled “GetDocumentAnalysis: Asynchronous Document Analysis”// initconst getDocumentAnalysis = yield* AWS.Textract.GetDocumentAnalysis();
// runtimeconst result = yield* getDocumentAnalysis({ JobId: jobId });if (result.JobStatus === "SUCCEEDED") { const blocks = result.Blocks;}GetDocumentTextDetection
Section titled “GetDocumentTextDetection”Source:
src/AWS/Textract/GetDocumentTextDetection.ts
Runtime binding for textract:GetDocumentTextDetection — read the
status and results of an asynchronous OCR job started with
StartDocumentTextDetection.
GetDocumentTextDetection: Asynchronous Text Detection
Section titled “GetDocumentTextDetection: Asynchronous Text Detection”// initconst getDocumentTextDetection = yield* AWS.Textract.GetDocumentTextDetection();
// runtimeconst result = yield* getDocumentTextDetection({ JobId: jobId });const lines = (result.Blocks ?? []) .filter((b) => b.BlockType === "LINE") .map((b) => b.Text);GetExpenseAnalysis
Section titled “GetExpenseAnalysis”Source:
src/AWS/Textract/GetExpenseAnalysis.ts
Runtime binding for textract:GetExpenseAnalysis — read the status and
results of an asynchronous expense-analysis job started with
StartExpenseAnalysis.
GetExpenseAnalysis: Asynchronous Expense Analysis
Section titled “GetExpenseAnalysis: Asynchronous Expense Analysis”// initconst getExpenseAnalysis = yield* AWS.Textract.GetExpenseAnalysis();
// runtimeconst result = yield* getExpenseAnalysis({ JobId: jobId });const documents = result.ExpenseDocuments;GetLendingAnalysis
Section titled “GetLendingAnalysis”Source:
src/AWS/Textract/GetLendingAnalysis.ts
Runtime binding for textract:GetLendingAnalysis — read the status and
per-page extraction results of an asynchronous lending-analysis job
started with StartLendingAnalysis.
GetLendingAnalysis: Asynchronous Lending Analysis
Section titled “GetLendingAnalysis: Asynchronous Lending Analysis”// initconst getLendingAnalysis = yield* AWS.Textract.GetLendingAnalysis();
// runtimeconst result = yield* getLendingAnalysis({ JobId: jobId });const pages = result.Results;GetLendingAnalysisSummary
Section titled “GetLendingAnalysisSummary”Source:
src/AWS/Textract/GetLendingAnalysisSummary.ts
Runtime binding for textract:GetLendingAnalysisSummary — read the
document-group summary of an asynchronous lending-analysis job started
with StartLendingAnalysis.
GetLendingAnalysisSummary: Asynchronous Lending Analysis
Section titled “GetLendingAnalysisSummary: Asynchronous Lending Analysis”// initconst getLendingAnalysisSummary = yield* AWS.Textract.GetLendingAnalysisSummary();
// runtimeconst result = yield* getLendingAnalysisSummary({ JobId: jobId });const groups = result.Summary?.DocumentGroups;ListAdapters
Section titled “ListAdapters”Source:
src/AWS/Textract/ListAdapters.ts
Runtime binding for textract:ListAdapters — list the Textract
adapters in the account/region.
ListAdapters: Managing Adapters
Section titled “ListAdapters: Managing Adapters”// initconst listAdapters = yield* AWS.Textract.ListAdapters();
// runtimeconst result = yield* listAdapters();const names = (result.Adapters ?? []).map((a) => a.AdapterName);ListAdapterVersions
Section titled “ListAdapterVersions”Source:
src/AWS/Textract/ListAdapterVersions.ts
Runtime binding for textract:ListAdapterVersions — list the versions
of the bound adapter and their training status.
ListAdapterVersions: Managing Adapters
Section titled “ListAdapterVersions: Managing Adapters”// initconst listAdapterVersions = yield* AWS.Textract.ListAdapterVersions(adapter);
// runtimeconst result = yield* listAdapterVersions();const versions = result.AdapterVersions;StartDocumentAnalysis
Section titled “StartDocumentAnalysis”Source:
src/AWS/Textract/StartDocumentAnalysis.ts
Runtime binding for textract:StartDocumentAnalysis — start an
asynchronous analysis job for a (possibly multi-page) document stored in
S3. Poll the returned JobId with GetDocumentAnalysis, or pass a
NotificationChannel to receive the completion event on an SNS topic
(pair it with an SNS event source to invoke a Function on completion).
The caller needs s3:GetObject on the input bucket.
StartDocumentAnalysis: Asynchronous Document Analysis
Section titled “StartDocumentAnalysis: Asynchronous Document Analysis”// initconst startDocumentAnalysis = yield* AWS.Textract.StartDocumentAnalysis();
// runtimeconst { JobId } = yield* startDocumentAnalysis({ DocumentLocation: { S3Object: { Bucket: bucketName, Name: "doc.pdf" } }, FeatureTypes: ["TABLES"],});StartDocumentTextDetection
Section titled “StartDocumentTextDetection”Source:
src/AWS/Textract/StartDocumentTextDetection.ts
Runtime binding for textract:StartDocumentTextDetection — start an
asynchronous OCR job for a (possibly multi-page) document stored in S3.
Poll the returned JobId with GetDocumentTextDetection. The caller
needs s3:GetObject on the input bucket.
StartDocumentTextDetection: Asynchronous Text Detection
Section titled “StartDocumentTextDetection: Asynchronous Text Detection”// initconst startDocumentTextDetection = yield* AWS.Textract.StartDocumentTextDetection();
// runtimeconst { JobId } = yield* startDocumentTextDetection({ DocumentLocation: { S3Object: { Bucket: bucketName, Name: "doc.pdf" } },});StartExpenseAnalysis
Section titled “StartExpenseAnalysis”Source:
src/AWS/Textract/StartExpenseAnalysis.ts
Runtime binding for textract:StartExpenseAnalysis — start an
asynchronous invoice/receipt analysis job for a document stored in S3.
Poll the returned JobId with GetExpenseAnalysis. The caller needs
s3:GetObject on the input bucket.
StartExpenseAnalysis: Asynchronous Expense Analysis
Section titled “StartExpenseAnalysis: Asynchronous Expense Analysis”// initconst startExpenseAnalysis = yield* AWS.Textract.StartExpenseAnalysis();
// runtimeconst { JobId } = yield* startExpenseAnalysis({ DocumentLocation: { S3Object: { Bucket: bucketName, Name: "invoice.pdf" } },});StartLendingAnalysis
Section titled “StartLendingAnalysis”Source:
src/AWS/Textract/StartLendingAnalysis.ts
Runtime binding for textract:StartLendingAnalysis — start an
asynchronous lending-document analysis job (classifies pages and routes
them to the right extraction model) for a document stored in S3. Poll
the returned JobId with GetLendingAnalysis /
GetLendingAnalysisSummary. The caller needs s3:GetObject on the
input bucket.
StartLendingAnalysis: Asynchronous Lending Analysis
Section titled “StartLendingAnalysis: Asynchronous Lending Analysis”// initconst startLendingAnalysis = yield* AWS.Textract.StartLendingAnalysis();
// runtimeconst { JobId } = yield* startLendingAnalysis({ DocumentLocation: { S3Object: { Bucket: bucketName, Name: "loan.pdf" } },});