Lädt...


🔧 How to Retrieve All DynamoDB Tables using JavaScript SDK v3 (2023)


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

In an engineering team with matured devops practices, it is often required to know all the DynamoDBs running in various accounts. This list of tables could then be used for:

  • Performing standard compliance checks on your table names and configuration.
  • Build alarm systems that monitors list of tables in a production account to make sure that every single table you need exists.
  • Creating backups and restoring data in DynamoDB tables.
  • Managing and organizing your DynamoDB tables.
  • Monitoring and optimizing performance of your DynamoDB tables.
  • Automating and integrating your application with other AWS services that use DynamoDB tables as input or output.
  • Auditing and tracking usage of your DynamoDB tables.

In this article, we'll be exploring how to retrieve all the DynamoDB table names using AWS SDK for JavaScript v3.

Before you start

I'd recommend using the latest version of NodeJS supported by Lambda Functions. It's also helpful to have nvm in your machine to easily switch between NodeJS versions.

# Install Node 18 to use the latest code-base
nvm install 18

node --version

# Switch to NodeJS 18
nvm use 18

You will have to install the JavaScript AWS SDKs v3 for DynamoDB. If you are using NPM, use the following commands to install the SDKs.

# If you use NPM
npm install @aws-sdk/client-dynamodb

# Install only if you want to use 
# named profiles inside your dev machine
npm install @aws-sdk/credential-providers

If you need to use yarn:

# If you use yarn
yarn add @aws-sdk/client-dynamodb

# Install only if you want to use inside your dev machine
yarn add @aws-sdk/credential-providers

The Source Code

By design, ListTablesCommand can only return a maximum of 100 DynamoDB names (see the code below).

import { DynamoDBClient, ListTablesCommand } from "@aws-sdk/client-dynamodb";
import { fromIni } from "@aws-sdk/credential-providers";

const client = new DynamoDBClient({ region: "ap-southeast-1" });

// Use this code if you need named profiles
// const client = new DynamoDBClient({
//   credentials: fromIni({ profile: "my-poc-profile" }),
//   region: "ap-southeast-1",
// });

const command = new ListTablesCommand({});
const response = await client.send(command);

console.log(response);

Which would result to:

{
  '$metadata': {
    httpStatusCode: 200,
    requestId: 'LKJEWJOI3290923902302310219',
    extendedRequestId: undefined,
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  },
  LastEvaluatedTableName: undefined,
  TableNames: [ 
    'dynamo-table-a', 
    'dynamo-table-b', 
    'dynamo-table-c'
   ]
}

The page limitation of 100 items per response is probably placed by AWS to gracefully handle accounts with large number of DynamoDB tables in them.

If you really want to retrieve all the tables in an account. You can use the following code instead:

import { DynamoDBClient, ListTablesCommand } from "@aws-sdk/client-dynamodb";
import { fromIni } from "@aws-sdk/credential-providers";

const client = new DynamoDBClient({
  credentials: fromIni({ profile: "my-poc-profile" }),
  region: "ap-southeast-1",
});
let startTableName = "";
let hasResults = false;
let tableNames = [];

do {
  hasResults = false;

  const searchInput = {
    Limit: 100,
  };

  if (startTableName) {
    searchInput.ExclusiveStartTableName = startTableName;
  }

  const command = new ListTablesCommand(searchInput);
  const response = await client.send(command);

  if (response.TableNames && response.TableNames.length > 0) {
    startTableName = response.TableNames[response.TableNames.length - 1];
    tableNames = [...tableNames, ...response.TableNames];
    hasResults = true;
  }
} while (hasResults);

console.log(tableNames);

Which would result to:

[ 'dynamo-table-a', 'dynamo-table-b', 'dynamo-table-c' ]
...

🔧 How to Retrieve All DynamoDB Tables using JavaScript SDK v3 (2023)


📈 81.44 Punkte
🔧 Programmierung

🔧 How to Apply Sorting on Tables in HTML Using JavaScript: Sortable Paginated Tables


📈 41.65 Punkte
🔧 Programmierung

🔧 [20 Days of DynamoDB] Day 12 - Using the DynamoDB expression package to build Projection expressions


📈 39.56 Punkte
🔧 Programmierung

🔧 [20 Days of DynamoDB] Day 5 - Avoid overwrites when using DynamoDB UpdateItem API


📈 39.56 Punkte
🔧 Programmierung

🔧 An ETL Job using AWS Glue Studio to inner join DynamoDB tables, Apply Queries and Store the result in S3


📈 37.32 Punkte
🔧 Programmierung

🔧 Using Mapping Tables to Merge Data with Auto-Number Keys Referenced by Other Tables


📈 35.07 Punkte
🔧 Programmierung

🔧 [20 Days of DynamoDB] Day 17 - DynamoDB BatchGetItem operation


📈 34.83 Punkte
🔧 Programmierung

🔧 DynamoDB Transactions: An E-Commerce with Amazon DynamoDB


📈 34.83 Punkte
🔧 Programmierung

🔧 DynamoDB Basic - Part 1: Introduction DynamoDB


📈 34.83 Punkte
🔧 Programmierung

🔧 Amazon DynamoDB announces new support for Attribute-Based Access Control (ABAC) for tables and indexes


📈 32.58 Punkte
🔧 Programmierung

🔧 Creating Secure Backups for DynamoDB Tables with Terraform


📈 32.58 Punkte
🔧 Programmierung

🔧 How to use AWS Backup cross-account backup to copy and restore DynamoDB tables between AWS accounts


📈 32.58 Punkte
🔧 Programmierung

🔧 HTML Tables: how to create and style tables with HTML


📈 30.33 Punkte
🔧 Programmierung

📰 Storytelling with Tables Part 1: Tables with Plotly


📈 30.33 Punkte
🔧 AI Nachrichten

🕵️ Low CVE-2015-9401: Websimon-tables project Websimon-tables


📈 30.33 Punkte
🕵️ Sicherheitslücken

🕵️ Medium CVE-2017-18597: Jtrt responsive tables project Jtrt responsive tables


📈 30.33 Punkte
🕵️ Sicherheitslücken

📰 Microsoft Excel Can Now Turn Pictures of Tables Into Actual, Editable Tables


📈 30.33 Punkte
📰 IT Security Nachrichten

🔧 DynamoDB Go SDK: How To Use the Scan and Batch Operations Efficiently


📈 27.36 Punkte
🔧 Programmierung

📰 DynamoDB Go SDK: How to Use the Scan and Batch Operations Efficiently


📈 27.36 Punkte
🔧 AI Nachrichten

🔧 How To Handle Type Conversions With the DynamoDB Go SDK


📈 27.36 Punkte
🔧 Programmierung

🔧 How to handle type conversions with the DynamoDB Go SDK


📈 27.36 Punkte
🔧 Programmierung

🐧 How to Use Pagination on HTML Tables Using JavaScript


📈 26.48 Punkte
🐧 Linux Tipps

📰 PowerShell: Retrieve and document all Hyper-V VMs


📈 24.52 Punkte
📰 IT Nachrichten

🔧 using slack api to retrieve data


📈 24.02 Punkte
🔧 Programmierung

🔧 Using JDBC to Retrieve Cursor Data in GBase 8c


📈 24.02 Punkte
🔧 Programmierung

🎥 Using For Loops in Azure Logic Apps retrieve Azure DevOps Work Items - No Code Micro Workshop Clip


📈 24.02 Punkte
🎥 Video | Youtube

🕵️ CVE-2023-43585 | Zoom Mobile App/Video SDK/Meeting SDK on iOS access control


📈 22.97 Punkte
🕵️ Sicherheitslücken

🕵️ CVE-2023-43583 | Zoom Mobile App/Video SDK/Meeting SDK on Android cryptographic issues


📈 22.97 Punkte
🕵️ Sicherheitslücken

🔧 How to build a zero-ETL DynamoDB integration with OpenSearch Service using AWS CDK


📈 22.15 Punkte
🔧 Programmierung

🔧 [20 Days of DynamoDB] Day 11 - Using pagination with Query API


📈 22.15 Punkte
🔧 Programmierung

matomo