

Ada lebih banyak contoh AWS SDK yang tersedia di repo Contoh [SDK AWS Doc](https://github.com/awsdocs/aws-doc-sdk-examples). GitHub 

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Amazon Kendra contoh menggunakan AWS CLI
<a name="cli_2_kendra_code_examples"></a>

Contoh kode berikut menunjukkan cara melakukan tindakan dan menerapkan skenario umum dengan menggunakan Amazon Kendra. AWS Command Line Interface 

*Tindakan* merupakan kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Sementara tindakan menunjukkan cara memanggil fungsi layanan individual, Anda dapat melihat tindakan dalam konteks dalam skenario terkait.

Setiap contoh menyertakan tautan ke kode sumber lengkap, di mana Anda dapat menemukan instruksi tentang cara mengatur dan menjalankan kode dalam konteks.

**Topics**
+ [Tindakan](#actions)

## Tindakan
<a name="actions"></a>

### `create-data-source`
<a name="kendra_CreateDataSource_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`create-data-source`.

**AWS CLI**  
**Untuk membuat konektor sumber data Amazon Kendra**  
Berikut ini `create-data-source` membuat dan mengkonfigurasi konektor sumber data Amazon Kendra. Anda dapat menggunakan `describe-data-source` untuk melihat status konektor sumber data, dan membaca pesan kesalahan apa pun jika status menunjukkan konektor sumber data “GAGAL” untuk sepenuhnya dibuat.  

```
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://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"]}'
```
Output:  

```
{
    "Id": "exampledatasource1"
}
```
Untuk informasi selengkapnya, lihat [Memulai indeks Amazon Kendra dan konektor sumber data di Panduan](https://docs.aws.amazon.com/kendra/latest/dg/getting-started.html) Pengembang *Amazon Kendra*.  
+  Untuk detail API, lihat [CreateDataSource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/kendra/create-data-source.html)di *Referensi AWS CLI Perintah*. 

### `create-index`
<a name="kendra_CreateIndex_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`create-index`.

**AWS CLI**  
**Untuk membuat indeks Amazon Kendra**  
Berikut ini `create-index` membuat dan mengkonfigurasi indeks Amazon Kendra. Anda dapat menggunakan `describe-index` untuk melihat status indeks, dan membaca pesan kesalahan apa pun jika status menunjukkan indeks “GAGAL” untuk sepenuhnya dibuat.  

```
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"}}'
```
Output:  

```
{
   "Id": index1
}
```
Untuk informasi selengkapnya, lihat [Memulai indeks Amazon Kendra dan konektor sumber data di Panduan](https://docs.aws.amazon.com/kendra/latest/dg/getting-started.html) Pengembang *Amazon Kendra*.  
+  Untuk detail API, lihat [CreateIndex](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/kendra/create-index.html)di *Referensi AWS CLI Perintah*. 

### `describe-data-source`
<a name="kendra_DescribeDataSource_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`describe-data-source`.

**AWS CLI**  
**Untuk mendapatkan informasi tentang konektor sumber data Amazon Kendra**  
Berikut ini `describe-data-source` mendapatkan informasi tentang konektor sumber data Amazon Kendra. Anda dapat melihat konfigurasi konektor sumber data, dan membaca pesan kesalahan apa pun jika status menunjukkan konektor sumber data “GAGAL” untuk sepenuhnya dibuat.  

```
aws kendra describe-data-source \
    --id exampledatasource1 \
    --index-id exampleindex1
```
Output:  

```
{
    "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"]
    }
}
```
Untuk informasi selengkapnya, lihat [Memulai indeks Amazon Kendra dan konektor sumber data di Panduan](https://docs.aws.amazon.com/kendra/latest/dg/getting-started.html) Pengembang *Amazon Kendra*.  
+  Untuk detail API, lihat [DescribeDataSource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/kendra/describe-data-source.html)di *Referensi AWS CLI Perintah*. 

### `describe-index`
<a name="kendra_DescribeIndex_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`describe-index`.

**AWS CLI**  
**Untuk mendapatkan informasi tentang indeks Amazon Kendra**  
Berikut ini `describe-index` mendapatkan informasi tentang indeks Amazon Kendra. Anda dapat melihat konfigurasi indeks, dan membaca pesan kesalahan apa pun jika status menunjukkan indeks “GAGAL” untuk sepenuhnya dibuat.  

```
aws kendra describe-index \
    --id exampleindex1
```
Output:  

```
{
    "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"
            }
        }
    ]
}
```
Untuk informasi selengkapnya, lihat [Memulai indeks Amazon Kendra dan konektor sumber data di Panduan](https://docs.aws.amazon.com/kendra/latest/dg/getting-started.html) Pengembang *Amazon Kendra*.  
+  Untuk detail API, lihat [DescribeIndex](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/kendra/describe-index.html)di *Referensi AWS CLI Perintah*. 

### `update-data-source`
<a name="kendra_UpdateDataSource_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`update-data-source`.

**AWS CLI**  
**Untuk memperbarui konektor sumber data Amazon Kendra**  
Berikut ini `update-data-source` memperbarui konfigurasi konektor sumber data Amazon Kendra. Jika tindakan berhasil, layanan mengirim kembali tidak ada output, kode status HTTP 200, atau kode pengembalian AWS CLI 0. Anda dapat menggunakan `describe-data-source` untuk melihat konfigurasi dan status konektor sumber data.  

```
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://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"]}'
```
Perintah ini tidak menghasilkan output.  
Untuk informasi selengkapnya, lihat [Memulai indeks Amazon Kendra dan konektor sumber data di Panduan](https://docs.aws.amazon.com/kendra/latest/dg/getting-started.html) Pengembang *Amazon Kendra*.  
+  Untuk detail API, lihat [UpdateDataSource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/kendra/update-data-source.html)di *Referensi AWS CLI Perintah*. 

### `update-index`
<a name="kendra_UpdateIndex_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`update-index`.

**AWS CLI**  
**Untuk memperbarui indeks Amazon Kendra**  
Berikut ini `update-index` memperbarui konfigurasi indeks Amazon Kendra. Jika tindakan berhasil, layanan mengirim kembali tidak ada output, kode status HTTP 200, atau kode pengembalian AWS CLI 0. Anda dapat menggunakan `describe-index` untuk melihat konfigurasi dan status indeks.  

```
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"}}'
```
Perintah ini tidak menghasilkan output.  
Untuk informasi selengkapnya, lihat [Memulai indeks Amazon Kendra dan konektor sumber data di Panduan](https://docs.aws.amazon.com/kendra/latest/dg/getting-started.html) Pengembang *Amazon Kendra*.  
+  Untuk detail API, lihat [UpdateIndex](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/kendra/update-index.html)di *Referensi AWS CLI Perintah*. 