2단계: 원장과의 연결을 테스트 - 아마존 퀀텀 레저 데이터베이스 (아마존QLDB)

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

2단계: 원장과의 연결을 테스트

중요

지원 종료 알림: 기존 고객은 2025년 7월 31일 지원이 종료될 QLDB 때까지 Amazon을 사용할 수 있습니다. 자세한 내용은 아마존 QLDB 원장을 Amazon Aurora SQL Postgre로 마이그레이션을 참조하십시오.

이 단계에서는 거래 데이터 엔드포인트를 QLDB 사용하여 Amazon의 vehicle-registration 원장에 연결할 수 있는지 확인합니다. API

원장과의 연결을 테스트하려면
  1. 다음 프로그램(ConnectToLedger.ts)을 사용하여 vehicle-registration 원장에 대한 데이터 세션 연결을 생성합니다.

    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. */ import { QldbDriver, RetryConfig } from "amazon-qldb-driver-nodejs"; import { ClientConfiguration } from "aws-sdk/clients/qldbsession"; import { LEDGER_NAME } from "./qldb/Constants"; import { error, log } from "./qldb/LogUtil"; const qldbDriver: QldbDriver = createQldbDriver(); /** * Create a driver for creating sessions. * @param ledgerName The name of the ledger to create the driver on. * @param serviceConfigurationOptions The configurations for the AWS SDK client that the driver uses. * @returns The driver for creating sessions. */ export function createQldbDriver( ledgerName: string = LEDGER_NAME, serviceConfigurationOptions: ClientConfiguration = {} ): QldbDriver { const retryLimit = 4; const maxConcurrentTransactions = 10; //Use driver's default backoff function (and hence, no second parameter provided to RetryConfig) const retryConfig: RetryConfig = new RetryConfig(retryLimit); const qldbDriver: QldbDriver = new QldbDriver(ledgerName, serviceConfigurationOptions, maxConcurrentTransactions, retryConfig); return qldbDriver; } export function getQldbDriver(): QldbDriver { return qldbDriver; } /** * Connect to a session for a given ledger using default settings. * @returns Promise which fulfills with void. */ const main = async function(): Promise<void> { try { log("Listing table names..."); const tableNames: string[] = await qldbDriver.getTableNames(); tableNames.forEach((tableName: string): void => { log(tableName); }); } catch (e) { error(`Unable to create session: ${e}`); } } if (require.main === module) { main(); }
    1.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. */ import { QldbDriver } from "amazon-qldb-driver-nodejs"; import { ClientConfiguration } from "aws-sdk/clients/qldbsession"; import { LEDGER_NAME } from "./qldb/Constants"; import { error, log } from "./qldb/LogUtil"; const qldbDriver: QldbDriver = createQldbDriver(); /** * Create a driver for creating sessions. * @param ledgerName The name of the ledger to create the driver on. * @param serviceConfigurationOptions The configurations for the AWS SDK client that the driver uses. * @returns The driver for creating sessions. */ export function createQldbDriver( ledgerName: string = LEDGER_NAME, serviceConfigurationOptions: ClientConfiguration = {} ): QldbDriver { const qldbDriver: QldbDriver = new QldbDriver(ledgerName, serviceConfigurationOptions); return qldbDriver; } export function getQldbDriver(): QldbDriver { return qldbDriver; } /** * Connect to a session for a given ledger using default settings. * @returns Promise which fulfills with void. */ var main = async function(): Promise<void> { try { log("Listing table names..."); const tableNames: string[] = await qldbDriver.getTableNames(); tableNames.forEach((tableName: string): void => { log(tableName); }); } catch (e) { error(`Unable to create session: ${e}`); } } if (require.main === module) { main(); }
    참고

    원장에서 데이터 거래를 실행하려면 지정된 원장에 연결할 QLDB 드라이버 객체를 생성해야 합니다. 이는 이전 단계에서 원장을 생성할 때 사용한 qldbClient 객체와는 다른 클라이언트 객체입니다. 이전 클라이언트는 에 나열된 관리 API 작업을 실행하는 데만 사용됩니다. 아마존 QLDB API 레퍼런스

  2. 트랜스파일된 프로그램을 실행하려면 다음 명령을 입력합니다.

    node dist/ConnectToLedger.js

vehicle-registration 원장에 테이블을 생성하려면 3단계: 테이블, 인덱스 및 샘플 데이터 생성로 진행하세요.