AWS CLI를 사용한 Amazon Kendra 예제 - AWS Command Line Interface

이 문서는 AWS CLI의 버전 1에만 해당합니다. AWS CLI의 버전 2와 관련된 문서는 버전 2 사용 설명서를 참조하세요.

AWS CLI를 사용한 Amazon Kendra 예제

다음 코드 예제에서는 Amazon Kendra에서 AWS Command Line Interface를 사용하여 작업을 수행하고 일반적인 시나리오를 구현하는 방법을 보여 줍니다.

작업은 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 작업은 개별 서비스 함수를 직접적으로 호출하는 방법을 보여주며 관련 시나리오의 컨텍스트에 맞는 작업을 볼 수 있습니다.

각 예제에는 컨텍스트에서 코드를 설정하고 실행하는 방법에 대한 지침을 찾을 수 있는 전체 소스 코드에 대한 링크가 포함되어 있습니다.

주제

작업

다음 코드 예제에서는 create-data-source을 사용하는 방법을 보여 줍니다.

AWS CLI

Amazon Kendra 데이터 소스 커넥터를 생성하는 방법

다음 create-data-source 코드는 Amazon Kendra 데이터 소스 커넥터를 만들고 구성합니다. describe-data-source를 사용하여 데이터 소스 커넥터의 상태를 확인하고, 상태에 데이터 소스 커넥터가 'FAILED'로 표시되면 오류 메시지를 읽어 완전히 생성할 수 있습니다.

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" }

자세한 내용은 Amazon Kendra 개발자 안내서의 Amazon Kendra 인덱스 및 데이터 소스 커넥터 시작하기를 참조하세요.

  • API 세부 정보는 AWS CLI 명령 참조의 CreateDataSource 섹션을 참조하세요.

다음 코드 예제에서는 create-index을 사용하는 방법을 보여 줍니다.

AWS CLI

Amazon Kendra 인덱스를 생성하는 방법

다음 create-index 코드는 Amazon Kendra 인덱스를 생성하고 구성합니다. describe-index를 사용하여 인덱스의 상태를 확인하고, 상태가 'FAILED'로 표시되면 오류 메시지를 읽어 완전히 생성합니다.

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 데이터 소스 커넥터에 대한 정보를 가져옵니다. 데이터 소스 커넥터의 구성을 확인하고, 상태에 데이터 소스 커넥터가 'FAILED'로 표시되면 오류 메시지를 읽어 완전히 생성할 수 있습니다.

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"] } }

자세한 내용은 Amazon Kendra 개발자 안내서의 Amazon Kendra 인덱스 및 데이터 소스 커넥터 시작하기를 참조하세요.

  • API 세부 정보는 AWS CLI 명령 참조의 DescribeDataSource 섹션을 참조하세요.

다음 코드 예제에서는 describe-index을 사용하는 방법을 보여 줍니다.

AWS CLI

Amazon Kendra 인덱스에 대한 정보를 가져오는 방법

다음 describe-index 코드는 Amazon Kendra 인덱스에 대한 정보를 가져옵니다. 인덱스의 구성을 확인하고, 상태가 'FAILED'로 표시되면 오류 메시지를 읽어 완전히 생성합니다.

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" } } ] }

자세한 내용은 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 \ --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"]}'

이 명령은 출력을 생성하지 않습니다.

자세한 내용은 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 \ --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"}}'

이 명령은 출력을 생성하지 않습니다.

자세한 내용은 Amazon Kendra 개발자 안내서의 Amazon Kendra 인덱스 및 데이터 소스 커넥터 시작하기를 참조하세요.

  • API 세부 정보는 AWS CLI 명령 참조의 UpdateIndex 섹션을 참조하세요.