通过 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)"