Wählen Sie Ihre Cookie-Einstellungen aus

Wir verwenden essentielle Cookies und ähnliche Tools, die für die Bereitstellung unserer Website und Services erforderlich sind. Wir verwenden Performance-Cookies, um anonyme Statistiken zu sammeln, damit wir verstehen können, wie Kunden unsere Website nutzen, und Verbesserungen vornehmen können. Essentielle Cookies können nicht deaktiviert werden, aber Sie können auf „Anpassen“ oder „Ablehnen“ klicken, um Performance-Cookies abzulehnen.

Wenn Sie damit einverstanden sind, verwenden AWS und zugelassene Drittanbieter auch Cookies, um nützliche Features der Website bereitzustellen, Ihre Präferenzen zu speichern und relevante Inhalte, einschließlich relevanter Werbung, anzuzeigen. Um alle nicht notwendigen Cookies zu akzeptieren oder abzulehnen, klicken Sie auf „Akzeptieren“ oder „Ablehnen“. Um detailliertere Entscheidungen zu treffen, klicken Sie auf „Anpassen“.

Erste Schritte (AWS SDK für Python (Boto3))

Fokusmodus
Erste Schritte (AWS SDK für Python (Boto3)) - Amazon Kendra

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

Das folgende Programm ist ein Beispiel für die Verwendung Amazon Kendra in einem Python-Programm. Das Programm führt die folgenden Aktionen aus:

  1. Erstellt mithilfe der CreateIndexOperation einen neuen Index.

  2. Wartet auf den Abschluss der Indexerstellung. Es verwendet den DescribeIndexVorgang, um den Status des Indexes zu überwachen.

  3. Sobald der Index aktiv ist, erstellt er mithilfe der CreateDataSourceOperation eine Datenquelle.

  4. Wartet, bis die Erstellung der Datenquelle abgeschlossen ist. Es verwendet den DescribeDataSourceVorgang, um den Status der Datenquelle zu überwachen.

  5. Wenn die Datenquelle aktiv ist, synchronisiert sie den Index mithilfe der StartDataSourceSyncJobOperation mit dem Inhalt der Datenquelle.

import boto3 from botocore.exceptions import ClientError import pprint import time kendra = boto3.client("kendra") print("Create an index.") # Provide a name for the index index_name = "python-getting-started-index" # Provide an optional decription for the index description = "Getting started index" # Provide the IAM role ARN required for indexes index_role_arn = "arn:aws:iam::${accountId}:role/KendraRoleForGettingStartedIndex" try: index_response = kendra.create_index( Description = description, Name = index_name, RoleArn = index_role_arn ) pprint.pprint(index_response) index_id = index_response["Id"] print("Wait for Amazon Kendra to create the index.") while True: # Get the details of the index, such as the status index_description = kendra.describe_index( Id = index_id ) # When status is not CREATING quit. status = index_description["Status"] print(" Creating index. Status: "+status) time.sleep(60) if status != "CREATING": break print("Create an S3 data source.") # Provide a name for the data source data_source_name = "python-getting-started-data-source" # Provide an optional description for the data source data_source_description = "Getting started data source." # Provide the IAM role ARN required for data sources data_source_role_arn = "arn:aws:iam::${accountId}:role/KendraRoleForGettingStartedDataSource" # Provide the data source connection information S3_bucket_name = "S3-bucket-name" data_source_type = "S3" # Configure the data source configuration = {"S3Configuration": { "BucketName": S3_bucket_name } } """ If you connect to your data source using a template schema, configure the template schema configuration = {"TemplateConfiguration": { "Template": {JSON schema} } } """ data_source_response = kendra.create_data_source( Name = data_source_name, Description = data_source_name, RoleArn = data_source_role_arn, Type = data_source_type, Configuration = configuration, IndexId = index_id ) pprint.pprint(data_source_response) data_source_id = data_source_response["Id"] print("Wait for Amazon Kendra to create the data source.") while True: # Get the details of the data source, such as the status data_source_description = kendra.describe_data_source( Id = data_source_id, IndexId = index_id ) # If status is not CREATING, then quit status = data_source_description["Status"] print(" Creating data source. Status: "+status) time.sleep(60) if status != "CREATING": break print("Synchronize the data source.") sync_response = kendra.start_data_source_sync_job( Id = data_source_id, IndexId = index_id ) pprint.pprint(sync_response) print("Wait for the data source to sync with the index.") while True: jobs = kendra.list_data_source_sync_jobs( Id = data_source_id, IndexId = index_id ) # For this example, there should be one job status = jobs["History"][0]["Status"] print(" Syncing data source. Status: "+status) if status != "SYNCING": break time.sleep(60) except ClientError as e: print("%s" % e) print("Program ends.")
DatenschutzNutzungsbedingungen für die WebsiteCookie-Einstellungen
© 2025, Amazon Web Services, Inc. oder Tochtergesellschaften. Alle Rechte vorbehalten.