使用 Amazon Kendra 的示例 Amazon CLI - Amazon Command Line Interface
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 Amazon Kendra 的示例 Amazon CLI

以下代码示例向您展示了如何在 Amazon Kendra 中 Amazon Command Line Interface 使用来执行操作和实现常见场景。

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景和跨服务示例的上下文查看操作。

场景是展示如何通过在同一服务中调用多个函数来完成特定任务任务的代码示例。

每个示例都包含一个指向的链接 GitHub,您可以在其中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示如何使用 create-data-source

Amazon CLI

创建 Amazon Kendra 数据源连接器

以下内容create-data-source创建和配置 Amazon Kendra 数据源连接器。您可以使用describe-data-source查看数据源连接器的状态,如果状态显示数据源连接器 “失败”,则可以读取任何错误消息,以完成创建。

aws kendra create-data-source \ --name "example data source 1" \ --description "Example data source 1 for example index 1 contains the first set of example documents" \ --tags '{"Key": "test resources", "Value": "kendra"}, {"Key": "test resources", "Value": "aws"}' \ --role-arn "arn:aws:iam::my-account-id:role/KendraRoleForS3TemplateConfigDataSource" \ --index-id exampleindex1 \ --language-code "es" \ --schedule "0 0 18 ? * TUE,MON,WED,THU,FRI,SAT *" \ --configuration '{"TemplateConfiguration": {"Template": file://s3schemaconfig.json}}' \ --type "TEMPLATE" \ --custom-document-enrichment-configuration '{"PostExtractionHookConfiguration": {"LambdaArn": "arn:aws:iam::my-account-id:function/my-function-ocr-docs", "S3Bucket": "s3://my-s3-bucket/scanned-image-text-example-docs"}, "RoleArn": "arn:aws:iam:my-account-id:role/KendraRoleForCDE"}' \ --vpc-configuration '{"SecurityGroupIds": ["sg-1234567890abcdef0"], "SubnetIds": ["subnet-1c234","subnet-2b134"]}'

输出:

{ "Id": "exampledatasource1" }

有关更多信息,请参阅《亚马逊 Kendra 开发者指南》中的 Amazon Kendra 索引和数据源连接器入门

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateDataSource中的。

以下代码示例演示如何使用 create-index

Amazon CLI

创建 Amazon Kendra 索引

以下内容create-index创建和配置 Amazon Kendra 索引。您可以使用describe-index查看索引的状态,如果状态显示索引为 “失败”,则可以读取任何错误消息,以便完全创建。

aws kendra create-index \ --name "example index 1" \ --description "Example index 1 contains the first set of example documents" \ --tags '{"Key": "test resources", "Value": "kendra"}, {"Key": "test resources", "Value": "aws"}' \ --role-arn "arn:aws:iam::my-account-id:role/KendraRoleForExampleIndex" \ --edition "DEVELOPER_EDITION" \ --server-side-encryption-configuration '{"KmsKeyId": "my-kms-key-id"}' \ --user-context-policy "USER_TOKEN" \ --user-token-configurations '{"JsonTokenTypeConfiguration": {"GroupAttributeField": "groupNameField", "UserNameAttributeField": "userNameField"}}'

输出:

{ "Id": index1 }

有关更多信息,请参阅《亚马逊 Kendra 开发者指南》中的 Amazon Kendra 索引和数据源连接器入门

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateIndex中的。

以下代码示例演示如何使用 describe-data-source

Amazon CLI

获取有关 Amazon Kendra 数据源连接器的信息

以下内容describe-data-source获取有关 Amazon Kendra 数据源连接器的信息。您可以查看数据源连接器的配置,如果状态显示数据源连接器 “失败”,则可以阅读任何错误消息,无法完全创建。

aws kendra describe-data-source \ --id exampledatasource1 \ --index-id exampleindex1

输出:

{ "Configuration": { "TemplateConfiguration": { "Template": { "connectionConfiguration": { "repositoryEndpointMetadata": { "BucketName": "my-bucket" } }, "repositoryConfigurations": { "document":{ "fieldMappings": [ { "indexFieldName":"_document_title", "indexFieldType":"STRING", "dataSourceFieldName": "title" }, { "indexFieldName":"_last_updated_at", "indexFieldType":"DATE", "dataSourceFieldName": "modified_date" } ] } }, "additionalProperties": { "inclusionPatterns": [ "*.txt", "*.doc", "*.docx" ], "exclusionPatterns": [ "*.json" ], "inclusionPrefixes": [ "PublicExampleDocsFolder" ], "exclusionPrefixes": [ "PrivateDocsFolder/private" ], "aclConfigurationFilePath": "ExampleDocsFolder/AclConfig.json", "metadataFilesPrefix": "metadata" }, "syncMode": "FULL_CRAWL", "type" : "S3", "version": "1.0.0" } } }, "CreatedAt": 2024-02-25T13:30:10+00:00, "CustomDocumentEnrichmentConfiguration": { "PostExtractionHookConfiguration": { "LambdaArn": "arn:aws:iam::my-account-id:function/my-function-ocr-docs", "S3Bucket": "s3://my-s3-bucket/scanned-image-text-example-docs/function" }, "RoleArn": "arn:aws:iam:my-account-id:role/KendraRoleForCDE" } "Description": "Example data source 1 for example index 1 contains the first set of example documents", "Id": exampledatasource1, "IndexId": exampleindex1, "LanguageCode": "en", "Name": "example data source 1", "RoleArn": "arn:aws:iam::my-account-id:role/KendraRoleForS3TemplateConfigDataSource", "Schedule": "0 0 18 ? * TUE,MON,WED,THU,FRI,SAT *", "Status": "ACTIVE", "Type": "TEMPLATE", "UpdatedAt": 1709163615, "VpcConfiguration": { "SecurityGroupIds": ["sg-1234567890abcdef0"], "SubnetIds": ["subnet-1c234","subnet-2b134"] } }

有关更多信息,请参阅《亚马逊 Kendra 开发者指南》中的 Amazon Kendra 索引和数据源连接器入门

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DescribeDataSource中的。

以下代码示例演示如何使用 describe-index

Amazon CLI

获取有关亚马逊 Kendra 索引的信息

以下内容describe-index获取有关亚马逊 Kendra 索引的信息。您可以查看索引的配置,如果状态显示索引为 “失败”,则可以阅读任何错误消息以完成创建。

aws kendra describe-index \ --id exampleindex1

输出:

{ "CapacityUnits": { "QueryCapacityUnits": 0, "StorageCapacityUnits": 0 }, "CreatedAt": 2024-02-25T12:30:10+00:00, "Description": "Example index 1 contains the first set of example documents", "DocumentMetadataConfigurations": [ { "Name": "_document_title", "Relevance": { "Importance": 8 }, "Search": { "Displayable": true, "Facetable": false, "Searchable": true, "Sortable": false }, "Type": "STRING_VALUE" }, { "Name": "_document_body", "Relevance": { "Importance": 5 }, "Search": { "Displayable": true, "Facetable": false, "Searchable": true, "Sortable": false }, "Type": "STRING_VALUE" }, { "Name": "_last_updated_at", "Relevance": { "Importance": 6, "Duration": "2628000s", "Freshness": true }, "Search": { "Displayable": true, "Facetable": false, "Searchable": true, "Sortable": true }, "Type": "DATE_VALUE" }, { "Name": "department_custom_field", "Relevance": { "Importance": 7, "ValueImportanceMap": { "Human Resources" : 4, "Marketing and Sales" : 2, "Research and innvoation" : 3, "Admin" : 1 } }, "Search": { "Displayable": true, "Facetable": true, "Searchable": true, "Sortable": true }, "Type": "STRING_VALUE" } ], "Edition": "DEVELOPER_EDITION", "Id": "index1", "IndexStatistics": { "FaqStatistics": { "IndexedQuestionAnswersCount": 10 }, "TextDocumentStatistics": { "IndexedTextBytes": 1073741824, "IndexedTextDocumentsCount": 1200 } }, "Name": "example index 1", "RoleArn": "arn:aws:iam::my-account-id:role/KendraRoleForExampleIndex", "ServerSideEncryptionConfiguration": { "KmsKeyId": "my-kms-key-id" }, "Status": "ACTIVE", "UpdatedAt": 1709163615, "UserContextPolicy": "USER_TOKEN", "UserTokenConfigurations": [ { "JsonTokenTypeConfiguration": { "GroupAttributeField": "groupNameField", "UserNameAttributeField": "userNameField" } } ] }

有关更多信息,请参阅《亚马逊 Kendra 开发者指南》中的 Amazon Kendra 索引和数据源连接器入门

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DescribeIndex中的。

以下代码示例演示如何使用 update-data-source

Amazon CLI

更新 Amazon Kendra 数据源连接器

以下内容update-data-source更新了 Amazon Kendra 数据源连接器的配置。如果操作成功,服务要么不发回任何输出,要么返回 HTTP 状态码 200,要么返回 Amazon CLI 返回代码 0。您可以使用describe-data-source查看数据源连接器的配置和状态。

aws kendra update-data-source \ --id exampledatasource1 \ --index-id exampleindex1 \ --name "new name for example data source 1" \ --description "new description for example data source 1" \ --role-arn arn:aws:iam::my-account-id:role/KendraNewRoleForExampleDataSource \ --configuration '{"TemplateConfiguration": {"Template": file://s3schemanewconfig.json}}' \ --custom-document-enrichment-configuration '{"PostExtractionHookConfiguration": {"LambdaArn": "arn:aws:iam::my-account-id:function/my-function-ocr-docs", "S3Bucket": "s3://my-s3-bucket/scanned-image-text-example-docs"}, "RoleArn": "arn:aws:iam:my-account-id:role/KendraNewRoleForCDE"}' \ --language-code "es" \ --schedule "0 0 18 ? * MON,WED,FRI *" \ --vpc-configuration '{"SecurityGroupIds": ["sg-1234567890abcdef0"], "SubnetIds": ["subnet-1c234","subnet-2b134"]}'

此命令不生成任何输出。

有关更多信息,请参阅《亚马逊 Kendra 开发者指南》中的 Amazon Kendra 索引和数据源连接器入门

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateDataSource中的。

以下代码示例演示如何使用 update-index

Amazon CLI

更新亚马逊 Kendra 索引

以下内容update-index更新了 Amazon Kendra 索引的配置。如果操作成功,服务要么不发回任何输出,要么返回 HTTP 状态码 200,要么返回 Amazon CLI 返回代码 0。您可以使用describe-index查看索引的配置和状态。

aws kendra update-index \ --id enterpriseindex1 \ --name "new name for Enterprise Edition index 1" \ --description "new description for Enterprise Edition index 1" \ --role-arn arn:aws:iam::my-account-id:role/KendraNewRoleForEnterpriseIndex \ --capacity-units '{"QueryCapacityUnits": 2, "StorageCapacityUnits": 1}' \ --document-metadata-configuration-updates '{"Name": "_document_title", "Relevance": {"Importance": 6}}, {"Name": "_last_updated_at", "Relevance": {"Importance": 8}}' \ --user-context-policy "USER_TOKEN" \ --user-token-configurations '{"JsonTokenTypeConfiguration": {"GroupAttributeField": "groupNameField", "UserNameAttributeField": "userNameField"}}'

此命令不生成任何输出。

有关更多信息,请参阅《亚马逊 Kendra 开发者指南》中的 Amazon Kendra 索引和数据源连接器入门

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateIndex中的。