How to get all fields present in aws-dynamoDB?

Viewed 8405

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.

3 Answers

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.

Related