2

I've taken a backup of a DynamoDB table in the AWS Console. I was able to download the file locally. I'd like to take that file and import it into a local dynamodb instance for testing. I've got far enough to create the table, however the backup json format doesn't seem to match nicely to the .NET AWS SDK APIs (thats a lot of TLAs).

Example backup contents:

{"Item":{"Attributes":{"M":{"createdAt":{"N":"1611923095468"},"eventDate":{"S":"2021-01-30T17:00:00.000Z"} }},"PartitionKey":{"S":"1234"},"SortKey":{"S":"1"}}}
{"Item":{"Attributes":{"M":{"createdAt":{"N":"1611923095468"},"eventDate":{"S":"2021-01-30T17:00:00.000Z"} }},"PartitionKey":{"S":"1234"},"SortKey":{"S":"2"}}}

The .NET APIs seem to want to convert the JSON in the non-dynamodb attribute format, so expect it like this:

{
    "Item": {
        "Attributes": {
            "createdAt": "1611923095468",
            "eventDate": "2021-01-30T17:00:00.000Z"
        },
        "PartitionKey": "1234",
        "SortKey": "1"
    }
}

So, I'd like to do something like:

var json = "{}"; // ORIGINAL CONCATENATED JSON FROM ABOVE 
Document.FromJson(json)

Is there some API that I'm missing that can convert this into some format that I can load into dynamodb? Again, using .NET, but open to any tools/utils for this.

brendonparker
  • 838
  • 8
  • 19

1 Answers1

1

This is the js script I came up with. Seemed to do the trick:

var DDB = require("@aws-sdk/client-dynamodb");
var fs = require('fs');
const ddb = new DDB.DynamoDB({ region: 'local', endpoint: 'http://localhost:8000' });

(async function test() {
    const text = fs.readFileSync('./bmorer2e5e3pfflf7qmuhhnpwy.json', 'utf8');

    text.toString().split('\n').map(async (line) => {
        if (line) await saveLine(line)
    });
})();

async function saveLine(line) {
    let item = JSON.parse(line);
    item.TableName = 'TABLE_NAME';
    item.ReturnConsumedCapacity = 'TOTAL';

    const res = await ddb.putItem(item);
    console.log(res.ConsumedCapacity);
}

brendonparker
  • 838
  • 8
  • 19