Passaggio 2: verifica la connettività al registro - Database Amazon Quantum Ledger (Amazon) QLDB

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Passaggio 2: verifica la connettività al registro

Importante

Avviso di fine del supporto: i clienti esistenti potranno utilizzare Amazon QLDB fino alla fine del supporto il 31/07/2025. Per ulteriori dettagli, consulta Migrare un Amazon QLDB Ledger ad Amazon Aurora Postgre. SQL

In questo passaggio, verifichi di poterti connettere al vehicle-registration registro di Amazon QLDB utilizzando l'endpoint dei dati transazionali. API

Per testare la connettività al registro
  1. Utilizzate il seguente programma (connect_to_ledger.py) per creare una connessione di sessione dati al vehicle-registration registro.

    3.x
    # Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 # # Permission is hereby granted, free of charge, to any person obtaining a copy of this # software and associated documentation files (the "Software"), to deal in the Software # without restriction, including without limitation the rights to use, copy, modify, # merge, publish, distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # This code expects that you have AWS credentials setup per: # https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html from logging import basicConfig, getLogger, INFO from botocore.exceptions import ClientError from pyqldb.driver.qldb_driver import QldbDriver from pyqldbsamples.constants import Constants logger = getLogger(__name__) basicConfig(level=INFO) def create_qldb_driver(ledger_name=Constants.LEDGER_NAME, region_name=None, endpoint_url=None, boto3_session=None): """ Create a QLDB driver for executing transactions. :type ledger_name: str :param ledger_name: The QLDB ledger name. :type region_name: str :param region_name: See [1]. :type endpoint_url: str :param endpoint_url: See [1]. :type boto3_session: :py:class:`boto3.session.Session` :param boto3_session: The boto3 session to create the client with (see [1]). :rtype: :py:class:`pyqldb.driver.qldb_driver.QldbDriver` :return: A QLDB driver object. [1]: `Boto3 Session.client Reference <https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html#boto3.session.Session.client>`. """ qldb_driver = QldbDriver(ledger_name=ledger_name, region_name=region_name, endpoint_url=endpoint_url, boto3_session=boto3_session) return qldb_driver def main(ledger_name=Constants.LEDGER_NAME): """ Connect to a given ledger using default settings. """ try: with create_qldb_driver(ledger_name) as driver: logger.info('Listing table names ') for table in driver.list_tables(): logger.info(table) except ClientError as ce: logger.exception('Unable to list tables.') raise ce if __name__ == '__main__': main()
    Nota
    • Per eseguire transazioni di dati sul registro, è necessario creare un oggetto QLDB driver per connettersi a un registro specifico. Si tratta di un oggetto client diverso dall'qldb_clientoggetto utilizzato nel passaggio precedente per creare il registro. Il client precedente viene utilizzato solo per eseguire le API operazioni di gestione elencate in. QLDBAPIRiferimento Amazon

    • È necessario specificare un nome contabile quando si crea questo oggetto driver.

    2.x
    # Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 # # Permission is hereby granted, free of charge, to any person obtaining a copy of this # software and associated documentation files (the "Software"), to deal in the Software # without restriction, including without limitation the rights to use, copy, modify, # merge, publish, distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # This code expects that you have AWS credentials setup per: # https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html from logging import basicConfig, getLogger, INFO from botocore.exceptions import ClientError from pyqldb.driver.pooled_qldb_driver import PooledQldbDriver from pyqldbsamples.constants import Constants logger = getLogger(__name__) basicConfig(level=INFO) def create_qldb_driver(ledger_name=Constants.LEDGER_NAME, region_name=None, endpoint_url=None, boto3_session=None): """ Create a QLDB driver for creating sessions. :type ledger_name: str :param ledger_name: The QLDB ledger name. :type region_name: str :param region_name: See [1]. :type endpoint_url: str :param endpoint_url: See [1]. :type boto3_session: :py:class:`boto3.session.Session` :param boto3_session: The boto3 session to create the client with (see [1]). :rtype: :py:class:`pyqldb.driver.pooled_qldb_driver.PooledQldbDriver` :return: A pooled QLDB driver object. [1]: `Boto3 Session.client Reference <https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html#boto3.session.Session.client>`. """ qldb_driver = PooledQldbDriver(ledger_name=ledger_name, region_name=region_name, endpoint_url=endpoint_url, boto3_session=boto3_session) return qldb_driver def create_qldb_session(): """ Retrieve a QLDB session object. :rtype: :py:class:`pyqldb.session.pooled_qldb_session.PooledQldbSession` :return: A pooled QLDB session object. """ qldb_session = pooled_qldb_driver.get_session() return qldb_session pooled_qldb_driver = create_qldb_driver() if __name__ == '__main__': """ Connect to a session for a given ledger using default settings. """ try: qldb_session = create_qldb_session() logger.info('Listing table names ') for table in qldb_session.list_tables(): logger.info(table) except ClientError: logger.exception('Unable to create session.')
    Nota
    • Per eseguire transazioni di dati sul registro, è necessario creare un oggetto QLDB driver per connettersi a un registro specifico. Si tratta di un oggetto client diverso dall'qldb_clientoggetto utilizzato nel passaggio precedente per creare il registro. Il client precedente viene utilizzato solo per eseguire le API operazioni di gestione elencate in. QLDBAPIRiferimento Amazon

    • Innanzitutto, create un oggetto QLDB driver condiviso. È necessario specificare un nome contabile quando si crea questo driver.

    • Quindi, è possibile creare sessioni da questo oggetto driver condiviso.

  2. Per eseguire il programma, immetti il comando seguente:

    python connect_to_ledger.py

Per creare tabelle nel vehicle-registration registro, procedi a. Passaggio 3: Creare tabelle, indici e dati di esempio