本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
建立資 Amazon S3 料來源
下列範例會示範建立 Amazon S3 資料來源。這些範例假設您已經建立索引和具有讀取索引資料之權限的 IAM 角色。如需有關 IAM 角色的詳細資訊,請參閱IAM 存取角色。如需有關建立索引的詳細資訊,請參閱建立索引。
- CLI
-
aws kendra create-data-source \ --index-id
index ID
\ --name example-data-source \ --type S3 \ --configuration '{"S3Configuration":{"BucketName":"bucket name
"}}' --role-arn 'arn:aws:iam::account id
:role:/role name
- Python
-
下面的 Python 代碼片段創建一個 Amazon S3 數據源。如需完整範例,請參閱開始使用 (AWS SDK for Python (Boto3))。
print("Create an Amazon S3 data source.") # Provide a name for the data source name = "getting-started-data-source" # Provide an optional description for the data source description = "Getting started data source." # Provide the IAM role ARN required for data sources role_arn = "arn:aws:iam::${accountID}:role/${roleName}" # Provide the data soource connection information s3_bucket_name = "S3-bucket-name" type = "S3" # Configure the data source configuration = {"S3DataSourceConfiguration": { "BucketName": s3_bucket_name } } data_source_response = kendra.create_data_source( Configuration = configuration, Name = name, Description = description, RoleArn = role_arn, Type = type, IndexId = index_id )
建立資料來源可能需要一些時間。您可以使用 DescribeDataSourceAPI 監控進度。當資料來源狀態為ACTIVE
資料來源可供使用時。
下列範例會示範取得資料來源的狀態。
- CLI
-
aws kendra describe-data-source \ --index-id
index ID
\ --iddata source ID
- Python
-
下列 Python 程式碼片段會取得 S3 資料來源的相關資訊。如需完整範例,請參閱開始使用 (AWS SDK for Python (Boto3))。
print("Wait for Amazon Kendra to create the data source.") while True: data_source_description = kendra.describe_data_source( Id = "
data-source-id
", IndexId = "index-id
" ) status = data_source_description["Status"] print(" Creating data source. Status: "+status) time.sleep(60) if status != "CREATING": break
此資料來源沒有排程,因此不會自動執行。若要為資料來源建立索引,StartDataSourceSyncJob請呼叫以將索引與資料來源同步化。
下列範例示範同步處理資料來源。
- CLI
-
aws kendra start-data-source-sync-job \ --index-id
index ID
\ --iddata source ID
- Python
-
下面的 Python 代碼片段同步的數 Amazon S3 據源。如需完整範例,請參閱開始使用 (AWS SDK for Python (Boto3))。
print("Synchronize the data source.") sync_response = kendra.start_data_source_sync_job( Id = "
data-source-id
", IndexId = "index-id
" )
Amazon S3
Amazon S3 文件元資料