Skip to content

AWS.Textract reference

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.

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" }],
},
});

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).

// init
const analyzeDocument = yield* AWS.Textract.AnalyzeDocument();
// runtime
const result = yield* analyzeDocument({
Document: { Bytes: documentBytes },
FeatureTypes: ["FORMS", "TABLES"],
});
const tables = (result.Blocks ?? []).filter((b) => b.BlockType === "TABLE");

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.

// init
const analyzeExpense = yield* AWS.Textract.AnalyzeExpense();
// runtime
const result = yield* analyzeExpense({
Document: { Bytes: receiptBytes },
});
const fields = result.ExpenseDocuments?.[0]?.SummaryFields;

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.

// init
const analyzeID = yield* AWS.Textract.AnalyzeID();
// runtime
const result = yield* analyzeID({
DocumentPages: [{ Bytes: licenseBytes }],
});
const fields = result.IdentityDocuments?.[0]?.IdentityDocumentFields;

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.

// init
const createAdapterVersion = yield* AWS.Textract.CreateAdapterVersion(adapter);
// runtime
const { AdapterVersion } = yield* createAdapterVersion({
DatasetConfig: {
ManifestS3Object: { Bucket: bucketName, Name: "manifest.jsonl" },
},
OutputConfig: { S3Bucket: bucketName, S3Prefix: "training-output/" },
});

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).

// init
const deleteAdapterVersion = yield* AWS.Textract.DeleteAdapterVersion(adapter);
// runtime
yield* deleteAdapterVersion({ AdapterVersion: "1" });

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”
// init
const detectDocumentText = yield* AWS.Textract.DetectDocumentText();
// runtime
const result = yield* detectDocumentText({
Document: { Bytes: documentBytes },
});
const lines = (result.Blocks ?? [])
.filter((block) => block.BlockType === "LINE")
.map((block) => block.Text);

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.

// init
const getAdapter = yield* AWS.Textract.GetAdapter(adapter);
// runtime
const result = yield* getAdapter();
console.log(result.AdapterName, result.FeatureTypes);

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.

// init
const getAdapterVersion = yield* AWS.Textract.GetAdapterVersion(adapter);
// runtime
const result = yield* getAdapterVersion({ AdapterVersion: "1" });
if (result.Status === "ACTIVE") {
// ready for AnalyzeDocument AdaptersConfig
}

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”
// init
const getDocumentAnalysis = yield* AWS.Textract.GetDocumentAnalysis();
// runtime
const result = yield* getDocumentAnalysis({ JobId: jobId });
if (result.JobStatus === "SUCCEEDED") {
const blocks = result.Blocks;
}

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”
// init
const getDocumentTextDetection =
yield* AWS.Textract.GetDocumentTextDetection();
// runtime
const result = yield* getDocumentTextDetection({ JobId: jobId });
const lines = (result.Blocks ?? [])
.filter((b) => b.BlockType === "LINE")
.map((b) => b.Text);

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”
// init
const getExpenseAnalysis = yield* AWS.Textract.GetExpenseAnalysis();
// runtime
const result = yield* getExpenseAnalysis({ JobId: jobId });
const documents = result.ExpenseDocuments;

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”
// init
const getLendingAnalysis = yield* AWS.Textract.GetLendingAnalysis();
// runtime
const result = yield* getLendingAnalysis({ JobId: jobId });
const pages = result.Results;

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”
// init
const getLendingAnalysisSummary =
yield* AWS.Textract.GetLendingAnalysisSummary();
// runtime
const result = yield* getLendingAnalysisSummary({ JobId: jobId });
const groups = result.Summary?.DocumentGroups;

Source: src/AWS/Textract/ListAdapters.ts

Runtime binding for textract:ListAdapters — list the Textract adapters in the account/region.

// init
const listAdapters = yield* AWS.Textract.ListAdapters();
// runtime
const result = yield* listAdapters();
const names = (result.Adapters ?? []).map((a) => a.AdapterName);

Source: src/AWS/Textract/ListAdapterVersions.ts

Runtime binding for textract:ListAdapterVersions — list the versions of the bound adapter and their training status.

// init
const listAdapterVersions = yield* AWS.Textract.ListAdapterVersions(adapter);
// runtime
const result = yield* listAdapterVersions();
const versions = result.AdapterVersions;

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”
// init
const startDocumentAnalysis = yield* AWS.Textract.StartDocumentAnalysis();
// runtime
const { JobId } = yield* startDocumentAnalysis({
DocumentLocation: { S3Object: { Bucket: bucketName, Name: "doc.pdf" } },
FeatureTypes: ["TABLES"],
});

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”
// init
const startDocumentTextDetection =
yield* AWS.Textract.StartDocumentTextDetection();
// runtime
const { JobId } = yield* startDocumentTextDetection({
DocumentLocation: { S3Object: { Bucket: bucketName, Name: "doc.pdf" } },
});

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”
// init
const startExpenseAnalysis = yield* AWS.Textract.StartExpenseAnalysis();
// runtime
const { JobId } = yield* startExpenseAnalysis({
DocumentLocation: { S3Object: { Bucket: bucketName, Name: "invoice.pdf" } },
});

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”
// init
const startLendingAnalysis = yield* AWS.Textract.StartLendingAnalysis();
// runtime
const { JobId } = yield* startLendingAnalysis({
DocumentLocation: { S3Object: { Bucket: bucketName, Name: "loan.pdf" } },
});