Sudhanshu
Sudhanshu

Reputation: 305

How to get all fields present in aws-dynamoDB?

I am using Node.js

var AWS = require('aws-sdk');

AWS.config.update({
  region: "region",
  endpoint: "https://dynamodb.region.amazonaws.com"
});
var dynamodb = new AWS.DynamoDB();
    var params = {
      TableName: "acc_new"
    };

    dynamodb.describeTable(params, function(err, data) {
        if (err) console.log(err, err.stack); // an error occurred
       else     console.log(JSON.stringify(data));
    });

Output :

{ AttributeDefinitions: [ { AttributeName: 'Id', AttributeType: 'S' } ],
  TableName: 'acc_new',
  KeySchema: [ { AttributeName: 'Id', KeyType: 'HASH' } ],
  ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 } }

output consist of only key schemas(hash and range keys only) associated with the table, Not all the attributes. I want to fetch all attributes associated with data in the table.

Like:

 { AttributeName: 'AccountName', AttributeType: 'S' }
 { AttributeName: 'CreatedBy', AttributeType: 'S' }
 ...
 ...

Is there any way to get descriptions of a dynamoDb table with all of its data fields.

Upvotes: 7

Views: 13223

Answers (3)

Garet Jax
Garet Jax

Reputation: 1171

There is no conventional way to do it, but here is how I would do it if you truly need it to be done:

  1. Create a DB table in a SQL DB that has 1 column with a PK on it.
  2. Extract all the data from the DynamoDB table using AWS Pipeline into an S3 bucket.
  3. Create a Lambda function that gets fired when a file is stored into the S3 bucket.
  4. The lambda function would do the following:

    • Retrieve all rows from the SQL DB created in (1)
    • Parse the file that fired it
    • Extract all column names from each row, 1 row at a time
    • Compare the column names to the ones found in the SQL DB table. If any are not found, then insert them into the SQL DB. Obviously duplicates would violate PK so be prepared to deal with that error.

In a couple of days or longer (depending on the number of rows), you would have all column names from the DynamoDB table stored in the SQL DB.

Upvotes: 1

Naveen Kerati
Naveen Kerati

Reputation: 971

For the above mentioned case it is not possible to list all the attributes in the table. Because Dynamodb is NoSql database attributes are defined in advance, only hash key and range key are defined when creating a table.

Upvotes: 0

notionquest
notionquest

Reputation: 39226

DynamoDB is a NoSQL database. While creating the table, it doesn't expect all the attributes to be defined in the table. Also, each item can have any number of non-key attributes. Only key attributes are common or mandatory across all the items in the table.

For the above mentioned reasons, the describe table can't provide all the attributes present in the table.

Upvotes: 3

Related Questions