Etapa 1: criar um novo ledger - Banco de dados Amazon Quantum Ledger (AmazonQLDB)

As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.

Etapa 1: criar um novo ledger

Importante

Aviso de fim do suporte: os clientes existentes poderão usar a Amazon QLDB até o final do suporte em 31/07/2025. Para obter mais detalhes, consulte Migrar um Amazon QLDB Ledger para o Amazon Aurora Postgre. SQL

Nesta etapa, você cria um novo QLDB livro contábil da Amazon chamadovehicle-registration.

Para criar um novo ledger
  1. Examine o arquivo a seguir (Constants.ts), que contém valores constantes usados por todos os outros programas deste 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";
  2. Use o programa a seguir (CreateLedger.ts) para criar um ledger chamado 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(); }
    nota
    • Na chamada createLedger, você deve especificar um nome de ledger e um modo de permissões. Recomendamos o uso do modo de permissões STANDARD para maximizar a segurança dos dados do seu ledger.

    • Ao criar um ledger, a proteção contra exclusão é habilitada, por padrão. Esse é um recurso QLDB que impede que os livros contábeis sejam excluídos por qualquer usuário. Você tem a opção de desativar a proteção contra exclusão na criação do livro contábil usando o QLDB API ou o AWS Command Line Interface ().AWS CLI

    • Se preferir, especifique também tags para anexar ao ledger.

  3. Para executar o programa transpilado, digite o comando a seguir.

    node dist/CreateLedger.js

Para verificar sua conexão com o novo ledger, vá para Etapa 2: Testar a conectividade com o ledger.