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
를 사용하여 데이터 소스 커넥터의 상태를 확인하고, 상태가 데이터 소스 커넥터 '실패'로 표시되는 경우 오류 메시지를 읽고 생성을 완료할 수 있습니다.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 \ --id
exampledatasource1
\ --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 \ --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-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 \ --id
enterpriseindex1
\ --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
를 참조하세요.
-