透過 CLI 處理 - Amazon Bedrock

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

透過 CLI 處理

透過 CLI 處理您的第一個文件

將檔案輸入 S3 儲存貯體

使用 BDA 處理文件之前,您必須先將文件上傳至 S3 儲存貯體:

語法

aws s3 cp <source> <target> [--options]

範例:

aws s3 cp /local/path/document.pdf s3://my-bda-bucket/input/document.pdf

基本處理命令結構

使用 invoke-data-automation-async命令來處理檔案:

aws bedrock-data-automation-runtime invoke-data-automation-async \ --input-configuration '{ "s3Uri": "s3://amzn-s3-demo-bucket/sample-images/sample-image.jpg" }' \ --output-configuration '{ "s3Uri": "s3://amzn-s3-demo-bucket/output/" }' \ --data-automation-configuration '{ "dataAutomationProjectArn": "Amazon Resource Name (ARN)", "stage": "LIVE" }' \ --data-automation-profile-arn "Amazon Resource Name (ARN)"

進階處理命令結構

使用時間區段處理影片

對於影片檔案,您可以指定要處理的時段:

aws bedrock-data-automation-runtime invoke-data-automation-async \ --input-configuration '{ "s3Uri": "s3://my-bucket/video.mp4", "assetProcessingConfiguration": { "video": { "segmentConfiguration": { "timestampSegment": { "startTimeMillis": 0, "endTimeMillis": 300000 } } } } }' \ --output-configuration '{ "s3Uri": "s3://my-bucket/output/" }' \ --data-automation-configuration '{ "dataAutomationProjectArn": "Amazon Resource Name (ARN)", "stage": "LIVE" }' \ --data-automation-profile-arn "Amazon Resource Name (ARN)"

使用自訂藍圖

您可以直接在 命令中指定自訂藍圖:

aws bedrock-data-automation-runtime invoke-data-automation-async \ --input-configuration '{ "s3Uri": "s3://my-bucket/document.pdf" }' \ --output-configuration '{ "s3Uri": "s3://my-bucket/output/" }' \ --blueprints '[ { "blueprintArn": "Amazon Resource Name (ARN)", "version": "1", "stage": "LIVE" } ]' \ --data-automation-profile-arn "Amazon Resource Name (ARN)"

新增加密組態

為了增強安全性,您可以新增加密組態:

aws bedrock-data-automation-runtime invoke-data-automation-async \ --input-configuration '{ "s3Uri": "s3://my-bucket/document.pdf" }' \ --output-configuration '{ "s3Uri": "s3://my-bucket/output/" }' \ --data-automation-configuration '{ "dataAutomationProjectArn": "Amazon Resource Name (ARN)", "stage": "LIVE" }' \ --encryption-configuration '{ "kmsKeyId": "Amazon Resource Name (ARN)", "kmsEncryptionContext": { "Department": "Finance", "Project": "DocumentProcessing" } }' \ --data-automation-profile-arn "Amazon Resource Name (ARN)"

事件通知

啟用 EventBridge 通知以完成處理:

aws bedrock-data-automation-runtime invoke-data-automation-async \ --input-configuration '{ "s3Uri": "s3://my-bucket/document.pdf" }' \ --output-configuration '{ "s3Uri": "s3://my-bucket/output/" }' \ --data-automation-configuration '{ "dataAutomationProjectArn": "Amazon Resource Name (ARN)", "stage": "LIVE" }' \ --notification-configuration '{ "eventBridgeConfiguration": { "eventBridgeEnabled": true } }' \ --data-automation-profile-arn "Amazon Resource Name (ARN)"

檢查處理狀態

使用 get-data-automation-status命令來檢查處理任務的狀態:

aws bedrock-data-automation-runtime get-data-automation-status \ --invocation-arn "Amazon Resource Name (ARN)"

回應將包含目前狀態:

{ "status": "COMPLETED", "creationTime": "2025-07-24T12:34:56.789Z", "lastModifiedTime": "2025-07-24T12:45:12.345Z", "outputLocation": "s3://my-bucket/output/abcd1234/" }

擷取處理結果

在 S3 中尋找輸出檔案

列出 S3 儲存貯體中的輸出檔案:

aws s3 ls s3://amzn-s3-demo-bucket/output/

將結果下載到您的本機電腦:

aws s3 cp s3://amzn-s3-demo-bucket/output/ ~/Downloads/bda-results/ --recursive

了解輸出結構

輸出通常包括:

  • standard-output.json:包含標準擷取結果

  • custom-output.json:包含自訂藍圖的結果

  • metadata.json:包含處理中繼資料和可信度分數

常見回應欄位

標準輸出通常包括:

  • extractedData:主要擷取的資訊

  • confidence:每個擷取欄位的可信度分數

  • metadata:處理資訊,包括時間戳記和模型詳細資訊

  • boundingBoxes:偵測到元素的位置資訊 (如果已啟用)

錯誤處理和疑難排解

常見的錯誤案例和解決方案:

  • 無效的 S3 URI:確保您的 S3 儲存貯體存在且您具有適當的許可

  • 缺少 data-automation-profile-arn:所有處理請求都需要此參數

  • 找不到專案:確認您的專案 ARN 正確且專案存在

  • 不支援的檔案格式:檢查 BDA 是否支援您的檔案格式

將標籤新增至處理任務

您可以新增標籤,以協助組織和追蹤處理任務:

aws bedrock-data-automation-runtime invoke-data-automation-async \ --input-configuration '{ "s3Uri": "s3://my-bucket/document.pdf" }' \ --output-configuration '{ "s3Uri": "s3://my-bucket/output/" }' \ --data-automation-configuration '{ "dataAutomationProjectArn": "Amazon Resource Name (ARN)", "stage": "LIVE" }' \ --tags '[ { "key": "Department", "value": "Finance" }, { "key": "Project", "value": "InvoiceProcessing" } ]' \ --data-automation-profile-arn "Amazon Resource Name (ARN)"