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à.
Fase 1: Creare un nuovo libro mastro
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
In questo passaggio, crei un nuovo QLDB registro Amazon denominatovehicle-registration
.
Per creare un nuovo libro mastro
-
Esamina il seguente file (
Constants.ts
), che contiene valori costanti utilizzati da tutti gli altri programmi di questo tutorial./* * 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";
-
Utilizzate il seguente programma (
CreateLedger.ts
) per creare un registro denominatovehicle-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(); }
Nota
-
Nella
createLedger
chiamata, è necessario specificare un nome di registro e una modalità di autorizzazione. Ti consigliamo di utilizzare la modalitàSTANDARD
autorizzazioni per massimizzare la sicurezza dei dati del registro. -
Quando si crea un registro, la protezione da eliminazione è abilitata per impostazione predefinita. Questa è una funzionalità QLDB che impedisce l'eliminazione dei registri da parte di qualsiasi utente. È possibile disabilitare la protezione da eliminazione durante la creazione di registri utilizzando QLDB API o il AWS Command Line Interface ().AWS CLI
-
Facoltativamente, puoi anche specificare dei tag da allegare al tuo libro mastro.
-
-
Per eseguire il programma transpiled, immettete il seguente comando.
node dist/CreateLedger.js
Per verificare la connessione al nuovo registro, procedi a. Passaggio 2: verifica la connettività al registro