

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

# 步骤 4：创建 Amazon Kendra 索引并提取元数据
<a name="tutorial-search-metadata-create-index-ingest"></a>

要实施您的智能搜索解决方案，您需要创建 Amazon Kendra 索引并将您的 S3 数据和元数据提取到该索引中。

在向 Amazon Kendra 索引添加元数据之前，您需要创建与自定义文档属性相对应的自定义索引字段，这些字段又对应于 Amazon Comprehend 实体类型。Amazon Kendra 使用您创建的索引字段和自定义文档属性来搜索和筛选您的文档。

有关更多信息，请参阅[索引](https://docs.aws.amazon.com/kendra/latest/dg/hiw-index.html)和[创建自定义文档属性](https://docs.aws.amazon.com/kendra/latest/dg/custom-attributes.html)。

**Topics**
+ [创建 Amazon Kendra 索引](#tutorial-search-metadata-create-index)
+ [更新 Amazon S3 访问的 IAM 角色](#tutorial-search-metadata-create-index-update-IAM)
+ [创建 Amazon Kendra 自定义搜索索引字段](#tutorial-search-metadata-create-index-custom-fields)
+ [添加 Amazon S3 存储桶作为索引的数据来源](#tutorial-search-metadata-create-index-connect-data)
+ [同步 Amazon Kendra 索引](#tutorial-search-metadata-create-index-sync)

## 创建 Amazon Kendra 索引
<a name="tutorial-search-metadata-create-index"></a>

要查询您的源文档，您需要创建 Amazon Kendra 索引。

如果您使用的是本步骤中的 AWS CLI ，则可以创建并附加一个 AWS IAM 角色和策略，允许 Amazon Kendra 在创建索引之前访问您的 CloudWatch 日志。有关更多信息，请参阅[先决条件](https://docs.aws.amazon.com/kendra/latest/dg/gs-prerequisites.html)。

### 创建 Amazon Kendra 索引（控制台）
<a name="tutorial-search-metadata-create-index-console"></a>

1. 打开亚马逊 Kendra 主机，网址为。[https://console.aws.amazon.com/kendra/](https://console.aws.amazon.com/kendra/)
**重要**  
确保您所在的区域与您创建 Amazon Comprehend 实体分析任务和 Amazon S3 存储桶所在的区域相同。如果您在其他区域，请从顶部导航栏的 AWS 区域选择**器中选择您创建 Amazon S3 存储桶的区域**。

1. 选择**创建索引**。

1. 要在**指定索引详细信息**页面上查看**索引详细信息**，请执行以下操作：

   1. 对于 **Index name (索引名称)**，输入 **kendra-index**。

   1. 将**描述**字段留空。

   1. 对于 **IAM 角色**，选择**创建新角色**。该角色提供对 Amazon S3 存储桶的访问权限。

   1. 对于**角色名称**，输入 **kendra-role**。IAM 角色将带有前缀 `AmazonKendra-`。

   1. 将**加密**和**标签**保留默认设置，然后选择**下一步**。

1. 对于**配置用户访问控制**页面上的**访问控制设置**，选择**否**，然后选择**下一步**。

1. 对于**预配详细信息**页面上的**预配版本**，请选择**开发者版本**并选择**创建**。

### 创建 Amazon Kendra 索引（AWS CLI）
<a name="tutorial-search-metadata-create-index-cli"></a>

1. 要为 Amazon Kendra 创建并附加将其识别为可信实体的 IAM 角色，请执行以下操作：

   1. 在本地设备上的文本编辑器中，将以下信任策略另存为名为 `kendra-trust-policy.json` 的 JSON 文件。

------
#### [ JSON ]

****  

      ```
      {
          "Version":"2012-10-17",		 	 	 
          "Statement": {
              "Effect": "Allow",
              "Principal": {
                  "Service": "kendra.amazonaws.com"
              },
              "Action": "sts:AssumeRole"
          }
      }
      ```

------

   1. 要创建名为 `kendra-role` 的 IAM 角色，并将您保存的 `kendra-trust-policy.json` 文件附加到该角色上，请使用 [create-role](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/create-role.html) 命令：

------
#### [ Linux ]

      ```
      aws iam create-role \
                --role-name kendra-role \
                --assume-role-policy-document file://path/kendra-trust-policy.json
      ```

      其中：
      + *path/*是本地设备`kendra-trust-policy.json`上的文件路径。

------
#### [ macOS ]

      ```
      aws iam create-role \
                --role-name kendra-role \
                --assume-role-policy-document file://path/kendra-trust-policy.json
      ```

      其中：
      + *path/*是本地设备`kendra-trust-policy.json`上的文件路径。

------
#### [ Windows ]

      ```
      aws iam create-role ^
                --role-name kendra-role ^
                --assume-role-policy-document file://path/kendra-trust-policy.json
      ```

      其中：
      + *path/*是本地设备`kendra-trust-policy.json`上的文件路径。

------

   1. 将 Amazon Resource Name（ARN）复制到您的文本编辑器中，并将其作为 `kendra-role-arn` 保存到本地。
**注意**  
ARN 具有类似于 *arn:aws:iam::123456789012:role/kendra-role* 的格式。您需要保存为 `kendra-role-arn` 的 ARN 才能运行 Amazon Kendra 作业。

1. 在创建索引之前，必须提供写入 CloudWatch 日志的权限。`kendra-role`为此，请完成以下步骤：

   1. 在本地设备上的文本编辑器中，将以下信任策略另存为名为 `kendra-cloudwatch-policy.json` 的 JSON 文件。

      *aws-region*替换为您所在的 AWS 地区和 12 位数*aws-account-id*的 AWS 账户 ID。

   1. 要创建用于访问 CloudWatch 日志的 IAM 策略，请使用 [create-policy 命令](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/create-policy.html)：

------
#### [ Linux ]

      ```
      aws iam create-policy \
                --policy-name kendra-cloudwatch-policy \
                --policy-document file://path/kendra-cloudwatch-policy.json
      ```

      其中：
      + *path/*是本地设备`kendra-cloudwatch-policy.json`上的文件路径。

------
#### [ macOS ]

      ```
      aws iam create-policy \
                --policy-name kendra-cloudwatch-policy \
                --policy-document file://path/kendra-cloudwatch-policy.json
      ```

      其中：
      + *path/*是本地设备`kendra-cloudwatch-policy.json`上的文件路径。

------
#### [ Windows ]

      ```
      aws iam create-policy ^
                --policy-name kendra-cloudwatch-policy ^
                --policy-document file://path/kendra-cloudwatch-policy.json
      ```

      其中：
      + *path/*是本地设备`kendra-cloudwatch-policy.json`上的文件路径。

------

   1. 将 Amazon Resource Name（ARN）复制到您的文本编辑器中，并将其作为 `kendra-cloudwatch-arn` 保存到本地。
**注意**  
ARN 具有类似于 *arn:aws:iam::123456789012:role/kendra-cloudwatch-policy* 的格式。您需要保存的 ARN 才能将 `kendra-cloudwatch-arn` 附加到您的 `kendra-cloudwatch-policy` IAM 角色。

   1. 要将附加`kendra-cloudwatch-policy`到您的 IAM 角色，请使用以下[attach-role-policy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/attach-role-policy.html)命令：

------
#### [ Linux ]

      ```
      aws iam attach-role-policy \
                --policy-arn policy-arn \
                --role-name kendra-role
      ```

      其中：
      + *policy-arn*你得救了吗`kendra-cloudwatch-arn`。

------
#### [ macOS ]

      ```
      aws iam attach-role-policy \
                --policy-arn policy-arn \
                --role-name kendra-role
      ```

      其中：
      + *policy-arn*你得救了吗`kendra-cloudwatch-arn`。

------
#### [ Windows ]

      ```
      aws iam attach-role-policy ^
                --policy-arn policy-arn ^
                --role-name kendra-role
      ```

      其中：
      + *policy-arn*你得救了吗`kendra-cloudwatch-arn`。

------

1. 要创建索引，请使用 [create-index](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/kendra/create-index.html) 命令：

------
#### [ Linux ]

   ```
   aws kendra create-index \
           --name kendra-index \
           --edition DEVELOPER_EDITION \
           --role-arn role-arn \
           --region aws-region
   ```

   其中：
   + *role-arn*你得救了吗`kendra-role-arn`，
   + *aws-region*是你所在 AWS 的地区。

------
#### [ macOS ]

   ```
   aws kendra create-index \
           --name kendra-index \
           --edition DEVELOPER_EDITION \
           --role-arn role-arn \
           --region aws-region
   ```

   其中：
   + *role-arn*你得救了吗`kendra-role-arn`，
   + *aws-region*是你所在 AWS 的地区。

------
#### [ Windows ]

   ```
   aws kendra create-index ^
           --name kendra-index ^
           --edition DEVELOPER_EDITION ^
           --role-arn role-arn ^
           --region aws-region
   ```

   其中：
   + *role-arn*你得救了吗`kendra-role-arn`，
   + *aws-region*是你所在 AWS 的地区。

------

1. 复制索引 `Id` 并将其作为 `kendra-index-id` 保存在文本编辑器中。`Id` 可帮助您跟踪索引创建的状态。

1. 要跟踪索引创建任务的进度，请使用 [describe-index](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/kendra/describe-index.html) 命令：

------
#### [ Linux ]

   ```
   aws kendra describe-index \
           --id kendra-index-id \
           --region aws-region
   ```

   其中：
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *aws-region*是你所在 AWS 的地区。

------
#### [ macOS ]

   ```
   aws kendra describe-index \
           --id kendra-index-id \
           --region aws-region
   ```

   其中：
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *aws-region*是你所在 AWS 的地区。

------
#### [ Windows ]

   ```
   aws kendra describe-index ^
           --id kendra-index-id ^
           --region aws-region
   ```

   其中：
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *aws-region*是你所在 AWS 的地区。

------

索引创建过程平均需要 15 分钟，但可能需要更长的时间。当索引的状态为活动时，您的索引就已经准备就绪。在创建索引的同时，您可以开始下一步。

如果您在此步骤 AWS CLI 中使用的是，则可以创建一个 IAM 策略并将其附加到您的 Amazon Kendra IAM 角色，该策略授予您的索引访问您的 S3 存储桶的权限。

## 更新 Amazon S3 访问的 IAM 角色
<a name="tutorial-search-metadata-create-index-update-IAM"></a>

在创建索引的同时，您可以更新您的 Amazon Kendra IAM 角色以允许您创建的索引从 Amazon S3 存储桶中读取数据。有关更多信息，请参阅 [Amazon Kendra 的 IAM 访问角色](https://docs.aws.amazon.com/kendra/latest/dg/iam-roles.html)。

### 更新 IAM 角色（控制台）
<a name="tutorial-search-metadata-update-role-console"></a>

1. 使用 [https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/) 打开 IAM 控制台。

1. 在左侧导航窗格中，选择**角色**，然后在**角色名称**上方的**搜索**框中输入 **kendra-role**。

1. 在建议的选项中，单击`kendra-role`。

1. 在**摘要**中，选择**附加策略**。

1. 在**附加权限**的**搜索**框中，从建议的选项中输入**S3**并选中 **AmazonS3 ReadOnlyAccess** 策略旁边的复选框。

1. 选择**附加策略**。现在，在**摘要**页面上，您将看到两个附加到 IAM 角色的策略。

1. 返回 Amazon Kendra 控制台 [https://console.aws.amazon.com/kendra/](https://console.aws.amazon.com/kendra/)，等待索引状态从 “**创建**” 变为 “**活动**”，然后再继续下一步操作。

### 更新 IAM 角色（AWS CLI）
<a name="tutorial-search-metadata-update-role-cli"></a>

1. 在本地设备上的文本编辑器中，将以下文本另存为名为 `kendra-S3-access-policy.json` 的 JSON 文件。

   将 amzn-s3-demo-bucket 替换为您的 S3 存储桶名称、*aws-region*您的 AWS 区域、12 位数*aws-account-id*的账户 ID 以及您保存 AWS 的。*kendra-index-id* `kendra-index-id`

1. 要创建 IAM policy 以访问 S3 桶，请使用 [create-policy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/create-policy.html) 命令：

------
#### [ Linux ]

   ```
   aws iam create-policy \
             --policy-name kendra-S3-access-policy \
             --policy-document file://path/kendra-S3-access-policy.json
   ```

   其中：
   + *path/*是本地设备`kendra-S3-access-policy.json`上的文件路径。

------
#### [ macOS ]

   ```
   aws iam create-policy \
             --policy-name kendra-S3-access-policy \
             --policy-document file://path/kendra-S3-access-policy.json
   ```

   其中：
   + *path/*是本地设备`kendra-S3-access-policy.json`上的文件路径。

------
#### [ Windows ]

   ```
   aws iam create-policy ^
             --policy-name kendra-S3-access-policy ^
             --policy-document file://path/kendra-S3-access-policy.json
   ```

   其中：
   + *path/*是本地设备`kendra-S3-access-policy.json`上的文件路径。

------

1. 将 Amazon Resource Name（ARN）复制到您的文本编辑器中，并将其作为 `kendra-S3-access-arn` 保存到本地。
**注意**  
ARN 具有类似于 *arn:aws:iam::123456789012:role/kendra-S3-access-policy* 的格式。您需要保存的 ARN 才能将 `kendra-S3-access-arn` 附加到您的 `kendra-S3-access-policy` IAM 角色。

1. 要将附加`kendra-S3-access-policy`到您的 Amazon Kendra IAM 角色，请使用以下[attach-role-policy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/attach-role-policy.html)命令：

------
#### [ Linux ]

   ```
   aws iam attach-role-policy \
             --policy-arn policy-arn \
             --role-name kendra-role
   ```

   其中：
   + *policy-arn*你得救了吗`kendra-S3-access-arn`。

------
#### [ macOS ]

   ```
   aws iam attach-role-policy \
             --policy-arn policy-arn \
             --role-name kendra-role
   ```

   其中：
   + *policy-arn*你得救了吗`kendra-S3-access-arn`。

------
#### [ Windows ]

   ```
   aws iam attach-role-policy ^
             --policy-arn policy-arn ^
             --role-name kendra-role
   ```

   其中：
   + *policy-arn*你得救了吗`kendra-S3-access-arn`。

------

## 创建 Amazon Kendra 自定义搜索索引字段
<a name="tutorial-search-metadata-create-index-custom-fields"></a>

要让 Amazon Kendra 做好将您的元数据识别为自定义文档属性的准备，您需要创建与 Amazon Comprehend 实体类型对应的自定义字段。您输入以下九种 Amazon Comprehend 实体类型作为自定义字段：
+ COMMERCIAL\$1ITEM
+ DATE
+ EVENT
+ LOCATION
+ ORGANIZATION
+ OTHER
+ PERSON
+ QUANTITY
+ TITLE

**重要**  
索引将无法识别拼写错误的实体类型。

### 为您的 Amazon Kendra 索引创建自定义字段（控制台）
<a name="tutorial-search-metadata-create-attributes-console"></a>

1. 打开亚马逊 Kendra 主机，网址为。[https://console.aws.amazon.com/kendra/](https://console.aws.amazon.com/kendra/)

1. 从**索引**列表中，单击`kendra-index`。

1. 在左侧导航面板的**数据管理**下，选择**分面定义**。

1. 从**索引字段**菜单中，选择**添加字段**。

1. 在**添加索引字段**对话框中，执行以下操作：

   1. 在**字段名称**中，输入 **COMMERCIAL\$1ITEM**。

   1. 在**数据类型**中，选择**字符串列表**。

   1. 在**使用类型**中，选择**可分面**、**可搜索**和**可显示**，然后选择**添加**。

   1. 对每种 Amazon Comprehend 实体类型重复步骤 a 到 c：COMMERCIAL\$1ITEM、DATE、EVENT、LOCATION、ORGANIZATION、OTHER、PERSON、QUANTITY、TITLE。

控制台显示成功添加字段的消息。在继续下一步之前，您可以选择将其关闭。

### 为您的 Amazon Kendra 索引（AWS CLI）创建自定义字段
<a name="tutorial-search-metadata-create-attributes-cli"></a>

1. 在本地设备上的文本编辑器中，将以下文本另存为名为 `custom-attributes.json` 的 JSON 文件。

   ```
   [
      {
          "Name": "COMMERCIAL_ITEM",
          "Type": "STRING_LIST_VALUE",
          "Search": {
              "Facetable": true,
              "Searchable": true,
              "Displayable": true
          }
      },
      {
          "Name": "DATE",
          "Type": "STRING_LIST_VALUE",
          "Search": {
              "Facetable": true,
              "Searchable": true,
              "Displayable": true
          }
      },
      {
          "Name": "EVENT",
          "Type": "STRING_LIST_VALUE",
          "Search": {
              "Facetable": true,
              "Searchable": true,
              "Displayable": true
          }
      },
      {
          "Name": "LOCATION",
          "Type": "STRING_LIST_VALUE",
          "Search": {
              "Facetable": true,
              "Searchable": true,
              "Displayable": true
          }
      },
      {
          "Name": "ORGANIZATION",
          "Type": "STRING_LIST_VALUE",
          "Search": {
              "Facetable": true,
              "Searchable": true,
              "Displayable": true
          }
      },
      {
          "Name": "OTHER",
          "Type": "STRING_LIST_VALUE",
          "Search": {
              "Facetable": true,
              "Searchable": true,
              "Displayable": true
          }
      },
      {
          "Name": "PERSON",
          "Type": "STRING_LIST_VALUE",
          "Search": {
              "Facetable": true,
              "Searchable": true,
              "Displayable": true
          }
      },
      {
          "Name": "QUANTITY",
          "Type": "STRING_LIST_VALUE",
          "Search": {
              "Facetable": true,
              "Searchable": true,
              "Displayable": true
          }
      },
      {
          "Name": "TITLE",
          "Type": "STRING_LIST_VALUE",
          "Search": {
              "Facetable": true,
              "Searchable": true,
              "Displayable": true
          }
      }
   ]
   ```

1. 要在索引中创建自定义字段，请使用 [update-index](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/kendra/update-index.html) 命令：

------
#### [ Linux ]

   ```
   aws kendra update-index \
           --id kendra-index-id \
           --document-metadata-configuration-updates file://path/custom-attributes.json \
           --region aws-region
   ```

   其中：
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *path/*是本地设备`custom-attributes.json`上的文件路径，
   + *aws-region*是你所在 AWS 的地区。

------
#### [ macOS ]

   ```
   aws kendra update-index \
           --id kendra-index-id \
           --document-metadata-configuration-updates file://path/custom-attributes.json \
           --region aws-region
   ```

   其中：
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *path/*是本地设备`custom-attributes.json`上的文件路径，
   + *aws-region*是你所在 AWS 的地区。

------
#### [ Windows ]

   ```
   aws kendra update-index ^
           --id kendra-index-id ^
           --document-metadata-configuration-updates file://path/custom-attributes.json ^
           --region aws-region
   ```

   其中：
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *path/*是本地设备`custom-attributes.json`上的文件路径，
   + *aws-region*是你所在 AWS 的地区。

------

1. 要验证自定义属性是否已添加到您的索引中，请使用 [describe-index](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/kendra/describe-index.html) 命令：

------
#### [ Linux ]

   ```
   aws kendra describe-index \
           --id kendra-index-id \
           --region aws-region
   ```

   其中：
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *aws-region*是你所在 AWS 的地区。

------
#### [ macOS ]

   ```
   aws kendra describe-index \
           --id kendra-index-id \
           --region aws-region
   ```

   其中：
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *aws-region*是你所在 AWS 的地区。

------
#### [ Windows ]

   ```
   aws kendra describe-index ^
           --id kendra-index-id ^
           --region aws-region
   ```

   其中：
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *aws-region*是你所在 AWS 的地区。

------

## 添加 Amazon S3 存储桶作为索引的数据来源
<a name="tutorial-search-metadata-create-index-connect-data"></a>

必须先将 S3 数据来源连接到索引，然后才能同步索引。

### 将 S3 存储桶连接到您的 Amazon Kendra 索引（控制台）
<a name="tutorial-search-metadata-connect-s3-console"></a>

1. 打开亚马逊 Kendra 主机，网址为。[https://console.aws.amazon.com/kendra/](https://console.aws.amazon.com/kendra/)

1. 从**索引**列表中，单击`kendra-index`。

1. 在左侧导航菜单的**数据管理**下，选择**数据来源**。

1. 在**选择数据来源连接器类型**部分下，导航到 **Amazon S3**，然后选择**添加连接器**。

1. 在**指定数据来源详细信息**页面中，执行以下操作：

   1. 在**名称和描述**下，对于**数据来源名称**，输入 **S3-data-source**。

   1. 将**描述**部分留空。

   1. 保留**标签**的默认设置。

   1. 选择**下一步**。

1. 在**配置同步设置**页面的**同步范围**部分，执行以下操作：

   1. 在**输入数据来源位置**中，选择**浏览 S3**。

   1. 在**选择资源**中，选择您的 S3 存储桶，然后点击**选择**。

   1. 在**元数据文件前缀文件夹位置**中，选择**浏览 S3**。

   1. 在**选择资源**中，从存储桶列表中单击存储桶的名称。

   1. 对于**对象**，选择 `metadata` 的选项框，然后单击**选择**。现在，位置字段应该显示 `metadata/`。

   1. 保留**访问控制列表配置文件位置**、**选择解密密钥**和**其他配置**的默认设置。

1. 对于 **IAM 角色**，在**配置同步设置**页面上，选择`kendra-role`。

1. 在**配置同步设置**页面的**同步运行计划**下，选择**频率**，选择**按需运行**，然后选择**下一步**。

1. 在**审核和创建**页面中，查看数据来源详细信息的选择，然后选择**添加数据来源**。

### 将 S3 存储桶连接到您的 Amazon Kendra 索引（AWS CLI）
<a name="tutorial-search-metadata-connect-s3-cli"></a>

1. 在本地设备上的文本编辑器中，将以下文本另存为名为 `S3-data-connector.json` 的 JSON 文件。

   ```
   {
      "S3Configuration":{
         "BucketName":"amzn-s3-demo-bucket",
         "DocumentsMetadataConfiguration":{
            "S3Prefix":"metadata"
         }
      }
   }
   ```

   将 amzn-s3-demo-bucket 替换为您的 S3 存储桶的名称。

1. 要将 S3 存储桶连接到索引，请使用以下[create-data-source](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/kendra/create-data-source.html)命令：

------
#### [ Linux ]

   ```
   aws kendra create-data-source \
           --index-id kendra-index-id \
           --name S3-data-source \
           --type S3 \
           --configuration file://path/S3-data-connector.json \
           --role-arn role-arn \
           --region aws-region
   ```

   其中：
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *path/*是本地设备`S3-data-connector.json`上的文件路径，
   + *role-arn*你得救了吗`kendra-role-arn`，
   + *aws-region*是你所在 AWS 的地区。

------
#### [ macOS ]

   ```
   aws kendra create-data-source \
           --index-id kendra-index-id \
           --name S3-data-source \
           --type S3 \
           --configuration file://path/S3-data-connector.json \
           --role-arn role-arn \
           --region aws-region
   ```

   其中：
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *path/*是本地设备`S3-data-connector.json`上的文件路径，
   + *role-arn*你得救了吗`kendra-role-arn`，
   + *aws-region*是你所在 AWS 的地区。

------
#### [ Windows ]

   ```
   aws kendra create-data-source ^
           --index-id kendra-index-id ^
           --name S3-data-source ^
           --type S3 ^
           --configuration file://path/S3-data-connector.json ^
           --role-arn role-arn ^
           --region aws-region
   ```

   其中：
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *path/*是本地设备`S3-data-connector.json`上的文件路径，
   + *role-arn*你得救了吗`kendra-role-arn`，
   + *aws-region*是你所在 AWS 的地区。

------

1. 复制连接器 `Id` 并将其作为 `S3-connector-id` 保存在文本编辑器中。`Id` 可帮助您跟踪数据连接过程的状态。

1. 要确保您的 S3 数据源已成功连接，请使用以下[describe-data-source](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/kendra/describe-data-source.html)命令：

------
#### [ Linux ]

   ```
   aws kendra describe-data-source \
           --id S3-connector-id \
           --index-id kendra-index-id \
           --region aws-region
   ```

   其中：
   + *S3-connector-id*你得救了吗`S3-connector-id`，
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *aws-region*是你所在 AWS 的地区。

------
#### [ macOS ]

   ```
   aws kendra describe-data-source \
           --id S3-connector-id \
           --index-id kendra-index-id \
           --region aws-region
   ```

   其中：
   + *S3-connector-id*你得救了吗`S3-connector-id`，
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *aws-region*是你所在 AWS 的地区。

------
#### [ Windows ]

   ```
   aws kendra describe-data-source ^
           --id S3-connector-id ^
           --index-id kendra-index-id ^
           --region aws-region
   ```

   其中：
   + *S3-connector-id*你得救了吗`S3-connector-id`，
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *aws-region*是你所在 AWS 的地区。

------

在此步骤结束时，您的 Amazon S3 数据来源已连接到索引。

## 同步 Amazon Kendra 索引
<a name="tutorial-search-metadata-create-index-sync"></a>

添加了 Amazon S3 数据来源后，您现在可以将您的 Amazon Kendra 索引同步到该数据来源。

### 同步您的 Amazon Kendra 索引（控制台）
<a name="tutorial-search-metadata-sync-index-console"></a>

1. 打开亚马逊 Kendra 主机，网址为。[https://console.aws.amazon.com/kendra/](https://console.aws.amazon.com/kendra/)

1. 从**索引**列表中，单击`kendra-index`。

1. 从左侧导航菜单中选择**数据来源**。

1. 在**数据来源**中选择 `S3-data-source`。

1. 从顶部导航栏中，选择**立即同步**。

### 同步您的 Amazon Kendra 索引（AWS CLI）
<a name="tutorial-search-metadata-sync-index-cli"></a>

1. 要同步索引，请使用 [start-data-source-sync-job](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/kendra/start-data-source-sync-job.html) 命令：

------
#### [ Linux ]

   ```
   aws kendra start-data-source-sync-job \
           --id S3-connector-id \
           --index-id kendra-index-id \
           --region aws-region
   ```

   其中：
   + *S3-connector-id*你得救了吗`S3-connector-id`，
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *aws-region*是你所在 AWS 的地区。

------
#### [ macOS ]

   ```
   aws kendra start-data-source-sync-job \
           --id S3-connector-id \
           --index-id kendra-index-id \
           --region aws-region
   ```

   其中：
   + *S3-connector-id*你得救了吗`S3-connector-id`，
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *aws-region*是你所在 AWS 的地区。

------
#### [ Windows ]

   ```
   aws kendra start-data-source-sync-job ^
           --id S3-connector-id ^
           --index-id kendra-index-id ^
           --region aws-region
   ```

   其中：
   + *S3-connector-id*你得救了吗`S3-connector-id`，
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *aws-region*是你所在 AWS 的地区。

------

1. 要检查索引同步的状态，请使用 [list-data-source-sync-jobs](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/kendra/list-data-source-sync-jobs.html) 命令：

------
#### [ Linux ]

   ```
   aws kendra list-data-source-sync-jobs \
           --id S3-connector-id \
           --index-id kendra-index-id \
           --region aws-region
   ```

   其中：
   + *S3-connector-id*你得救了吗`S3-connector-id`，
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *aws-region*是你所在 AWS 的地区。

------
#### [ macOS ]

   ```
   aws kendra list-data-source-sync-jobs \
           --id S3-connector-id \
           --index-id kendra-index-id \
           --region aws-region
   ```

   其中：
   + *S3-connector-id*你得救了吗`S3-connector-id`，
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *aws-region*是你所在 AWS 的地区。

------
#### [ Windows ]

   ```
   aws kendra list-data-source-sync-jobs ^
           --id S3-connector-id ^
           --index-id kendra-index-id ^
           --region aws-region
   ```

   其中：
   + *S3-connector-id*你得救了吗`S3-connector-id`，
   + *kendra-index-id*你得救了吗`kendra-index-id`，
   + *aws-region*是你所在 AWS 的地区。

------

在本步骤结束时，您已经为您的数据集创建了一个可搜索和可筛选的 Amazon Kendra 索引。