I am using aws-sdk for nodejs in a project, and not finding any way to fetch all tables from an endpoint, in other words I am looking forward for equivalent of following command in SDK.
aws dynamodb list-tables --endpoint-url <ENDPOINT_URL>
Any help is much appreciated.
Regards.
Returns an array of table names associated with the current account and endpoint. The output from ListTables is paginated, with each page returning a maximum of 100 table names.
DynamoDB supports the Java Set , List , and Map collection types. The following table summarizes how these Java types map to the DynamoDB types.
The Query operation in Amazon DynamoDB finds items based on primary key values. You must provide the name of the partition key attribute and a single value for that attribute. Query returns all items with that partition key value.
If you have more than 100 tables, then you also need to be aware of pagination. You can use this example for Node.js:
const readAllTables = async() => {
const AWS = require("aws-sdk");
var dynamodb = new AWS.DynamoDB();
var params = {};
var tables = [];
while(true) {
var response = await dynamodb.listTables(params).promise();
tables = tables.concat(response.TableNames);
if (undefined === response.LastEvaluatedTableName) {
break;
} else {
params.ExclusiveStartTableName = response.LastEvaluatedTableName;
}
}
return tables;
}
Thanks friends, I found the solution as
const AWS = require("aws-sdk");
var dynamodb = new AWS.DynamoDB();
var param = {}
dynamodb.listTables(param, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With