ステップ 1: 新しい台帳を作成する - Amazon Quantum 台帳データベース (Amazon QLDB)

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

ステップ 1: 新しい台帳を作成する

重要

サポート終了通知: 既存のお客様は、07/31/2025 のサポート終了QLDBまで Amazon を使用できます。詳細については、「Amazon Ledger QLDB を Amazon Aurora Postgre に移行するSQL」を参照してください。

このステップでは、 という名前の新しい Amazon QLDB台帳を作成しますvehicle-registration

新しい台帳を作成するには
  1. 次のファイル (Constants.ts) を確認します。このファイルには、このチュートリアル内の他のすべてのプログラムで使用される定数値が含まれています。

    /* * 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. */ /** * Constant values used throughout this tutorial. */ export const LEDGER_NAME = "vehicle-registration"; export const LEDGER_NAME_WITH_TAGS = "tags"; export const DRIVERS_LICENSE_TABLE_NAME = "DriversLicense"; export const PERSON_TABLE_NAME = "Person"; export const VEHICLE_REGISTRATION_TABLE_NAME = "VehicleRegistration"; export const VEHICLE_TABLE_NAME = "Vehicle"; export const GOV_ID_INDEX_NAME = "GovId"; export const LICENSE_NUMBER_INDEX_NAME = "LicenseNumber"; export const LICENSE_PLATE_NUMBER_INDEX_NAME = "LicensePlateNumber"; export const PERSON_ID_INDEX_NAME = "PersonId"; export const VIN_INDEX_NAME = "VIN"; export const RETRY_LIMIT = 4; export const JOURNAL_EXPORT_S3_BUCKET_NAME_PREFIX = "qldb-tutorial-journal-export"; export const USER_TABLES = "information_schema.user_tables";
  2. 次のプログラム (CreateLedger.ts) を使用して、vehicle-registration という名前の台帳を作成します。

    /* * 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 { QLDB } from "aws-sdk"; import { CreateLedgerRequest, CreateLedgerResponse, DescribeLedgerRequest, DescribeLedgerResponse } from "aws-sdk/clients/qldb"; import { LEDGER_NAME } from "./qldb/Constants"; import { error, log } from "./qldb/LogUtil"; import { sleep } from "./qldb/Util"; const LEDGER_CREATION_POLL_PERIOD_MS = 10000; const ACTIVE_STATE = "ACTIVE"; /** * Create a new ledger with the specified name. * @param ledgerName Name of the ledger to be created. * @param qldbClient The QLDB control plane client to use. * @returns Promise which fulfills with a CreateLedgerResponse. */ export async function createLedger(ledgerName: string, qldbClient: QLDB): Promise<CreateLedgerResponse> { log(`Creating a ledger named: ${ledgerName}...`); const request: CreateLedgerRequest = { Name: ledgerName, PermissionsMode: "ALLOW_ALL" } const result: CreateLedgerResponse = await qldbClient.createLedger(request).promise(); log(`Success. Ledger state: ${result.State}.`); return result; } /** * Wait for the newly created ledger to become active. * @param ledgerName Name of the ledger to be checked on. * @param qldbClient The QLDB control plane client to use. * @returns Promise which fulfills with a DescribeLedgerResponse. */ export async function waitForActive(ledgerName: string, qldbClient: QLDB): Promise<DescribeLedgerResponse> { log(`Waiting for ledger ${ledgerName} to become active...`); const request: DescribeLedgerRequest = { Name: ledgerName } while (true) { const result: DescribeLedgerResponse = await qldbClient.describeLedger(request).promise(); if (result.State === ACTIVE_STATE) { log("Success. Ledger is active and ready to be used."); return result; } log("The ledger is still creating. Please wait..."); await sleep(LEDGER_CREATION_POLL_PERIOD_MS); } } /** * Create a ledger and wait for it to be active. * @returns Promise which fulfills with void. */ const main = async function(): Promise<void> { try { const qldbClient: QLDB = new QLDB(); await createLedger(LEDGER_NAME, qldbClient); await waitForActive(LEDGER_NAME, qldbClient); } catch (e) { error(`Unable to create the ledger: ${e}`); } } if (require.main === module) { main(); }
    注記
    • createLedger の呼び出しで、台帳名とアクセス許可モードを指定する必要があります。台帳データのセキュリティを最大化する、STANDARD のアクセス許可モードの使用を推奨します。

    • 台帳を作成すると、デフォルトで削除保護が有効になります。これは、台帳QLDBがどのユーザーによっても削除されないようにする の機能です。QLDB API または AWS Command Line Interface () を使用して、台帳の作成時に削除保護を無効にすることができますAWS CLI。

    • 必要に応じて、台帳にアタッチするタグを指定することもできます。

  3. トランスパイルされたプログラムを実行するには、次のコマンドを入力します。

    node dist/CreateLedger.js

新しい台帳への接続を確認するには、「ステップ 2: 台帳への接続をテストする」に進みます。