使用 AWS CLI 的 Amazon Kendra 示例
以下代码示例演示了如何通过将 AWS Command Line Interface与 Amazon Kendra 结合使用,来执行操作和实现常见场景。
操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。
每个示例都包含一个指向完整源代码的链接,您可以从中找到有关如何在上下文中设置和运行代码的说明。
主题
操作
以下代码示例演示了如何使用 create-data-source。
- AWS 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-idexampleindex1\ --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://amzn-s3-demo-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" }有关更多信息,请参阅《Amazon Kendra 开发人员指南》中的 Amazon Kendra 索引和数据来源连接器入门。 - 
                    有关 API 详细信息,请参阅《AWS CLI 命令参考》中的 CreateDataSource 。 
 
- 
                    
以下代码示例演示了如何使用 create-index。
- AWS 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 }有关更多信息,请参阅《Amazon Kendra 开发人员指南》中的 Amazon Kendra 索引和数据来源连接器入门。 - 
                    有关 API 详细信息,请参阅《AWS CLI 命令参考》中的 CreateIndex 。 
 
- 
                    
以下代码示例演示了如何使用 describe-data-source。
- AWS CLI
- 
             
                    获取有关 Amazon Kendra 数据来源连接器的信息 以下 describe-data-source命令获取有关 Amazon Kendra 数据来源连接器的信息。您可以查看数据来源连接器的配置,如果状态显示创建数据来源连接器“失败”,则读取相关错误消息。aws kendra describe-data-source \ --idexampledatasource1\ --index-idexampleindex1输出: { "Configuration": { "TemplateConfiguration": { "Template": { "connectionConfiguration": { "repositoryEndpointMetadata": { "BucketName": "amzn-s3-demo-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://amzn-s3-demo-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"] } }有关更多信息,请参阅《Amazon Kendra 开发人员指南》中的 Amazon Kendra 索引和数据来源连接器入门。 - 
                    有关 API 详细信息,请参阅《AWS CLI 命令参考》中的 DescribeDataSource 。 
 
- 
                    
以下代码示例演示了如何使用 describe-index。
- AWS CLI
- 
             
                    获取有关 Amazon Kendra 索引的信息 以下 describe-index命令获取有关 Amazon Kendra 索引的信息。您可以查看索引的配置,如果状态显示创建索引“失败”,则读取相关错误消息。aws kendra describe-index \ --idexampleindex1输出: { "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" } } ] }有关更多信息,请参阅《Amazon Kendra 开发人员指南》中的 Amazon Kendra 索引和数据来源连接器入门。 - 
                    有关 API 详细信息,请参阅《AWS CLI 命令参考》中的 DescribeIndex 。 
 
- 
                    
以下代码示例演示了如何使用 update-data-source。
- AWS CLI
- 
             
                    更新 Amazon Kendra 数据来源连接器 以下 update-data-source命令更新 Amazon Kendra 数据来源连接器的配置。如果操作成功,则服务发回 HTTP 状态码 200 而无任何输出,或者 AWS CLI 返回代码 0。您可以使用describe-data-source查看数据来源连接器的配置和状态。aws kendra update-data-source \ --idexampledatasource1\ --index-idexampleindex1\ --name"new name for example data source 1"\ --description"new description for example data source 1"\ --role-arnarn: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://amzn-s3-demo-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"]}'此命令不生成任何输出。 有关更多信息,请参阅《Amazon Kendra 开发人员指南》中的 Amazon Kendra 索引和数据来源连接器入门。 - 
                    有关 API 详细信息,请参阅《AWS CLI 命令参考》中的 UpdateDataSource 。 
 
- 
                    
以下代码示例演示了如何使用 update-index。
- AWS CLI
- 
             
                    更新 Amazon Kendra 索引 以下 update-index命令更新 Amazon Kendra 索引的配置。如果操作成功,则服务发回 HTTP 状态码 200 而无任何输出,或者 AWS CLI 返回代码 0。您可以使用describe-index查看索引的配置和状态。aws kendra update-index \ --identerpriseindex1\ --name"new name for Enterprise Edition index 1"\ --description"new description for Enterprise Edition index 1"\ --role-arnarn: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"}}'此命令不生成任何输出。 有关更多信息,请参阅《Amazon Kendra 开发人员指南》中的 Amazon Kendra 索引和数据来源连接器入门。 - 
                    有关 API 详细信息,请参阅《AWS CLI 命令参考》中的 UpdateIndex 。 
 
-