Step 9 (optional): Clean up resources - Amazon Quantum Ledger Database (Amazon QLDB)

Step 9 (optional): Clean up resources

You can continue using the vehicle-registration ledger. However, if you no longer need it, you should delete it.

To delete the ledger
  1. Compile and run the following program ( to delete your vehicle-registration ledger and all of its contents.

    /* * Copyright 2019, 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. */ package; import; import; import; import; import; import; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Delete a ledger. * * This code expects that you have AWS credentials setup per: * */ public final class DeleteLedger { public static final Logger log = LoggerFactory.getLogger(DeleteLedger.class); public static final Long LEDGER_DELETION_POLL_PERIOD_MS = 20_000L; public static AmazonQLDB client = CreateLedger.getClient(); private DeleteLedger() { } public static void main(String... args) throws Exception { try { setDeletionProtection(Constants.LEDGER_NAME, false); delete(Constants.LEDGER_NAME); waitForDeleted(Constants.LEDGER_NAME); } catch (Exception e) { log.error("Unable to delete the ledger.", e); throw e; } } /** * Send a request to the QLDB database to delete the specified ledger. * * @param ledgerName * Name of the ledger to be deleted. * @return DeleteLedgerResult. */ public static DeleteLedgerResult delete(final String ledgerName) {"Attempting to delete the ledger with name: {}...", ledgerName); DeleteLedgerRequest request = new DeleteLedgerRequest().withName(ledgerName); DeleteLedgerResult result = client.deleteLedger(request);"Success."); return result; } /** * Wait for the ledger to be deleted. * * @param ledgerName * Name of the ledger being deleted. * @throws InterruptedException if thread is being interrupted. */ public static void waitForDeleted(final String ledgerName) throws InterruptedException {"Waiting for the ledger to be deleted..."); while (true) { try { DescribeLedger.describe(ledgerName);"The ledger is still being deleted. Please wait..."); Thread.sleep(LEDGER_DELETION_POLL_PERIOD_MS); } catch (ResourceNotFoundException ex) {"Success. The ledger is deleted."); break; } } } public static UpdateLedgerResult setDeletionProtection(String ledgerName, boolean deletionProtection) {"Let's set deletionProtection to {} for the ledger with name {}", deletionProtection, ledgerName); UpdateLedgerRequest request = new UpdateLedgerRequest() .withName(ledgerName) .withDeletionProtection(deletionProtection); UpdateLedgerResult result = client.updateLedger(request);"Success. Ledger updated: {}", result); return result; } }

    If deletion protection is enabled for your ledger, you must first disable it before you can delete the ledger using the QLDB API.

  2. If you exported journal data in the previous step and no longer need it, use the Amazon S3 console to delete your S3 bucket.

    Open the Amazon S3 console at