Importar datos JSON en la tabla (DynamoDB, nodeJS)

Quiero importar datos de mi archivo JSON a DynamoDB con este código:

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

AWS.config.update({
    region: "us-west-2",
    endpoint: "http://localhost:8000"
});

var docClient = new AWS.DynamoDB.DocumentClient();

console.log("Importing Pays into DynamoDB. Please wait.");

var allPays = JSON.parse(fs.readFileSync('paysdata.JSON', 'utf8'));
allPays.forEach(function(pays) {
    var params = {
        TableName: "Pays",
        Item: {
            "region":  pays.region,
            "name": pays.name,
            "name.common": pays.name.common,
            "languages":  pays.languages,
            "area": pays.area
        }
    };

    docClient.put(params, function(err, data) {
       if (err) {
           console.error("Unable to add Pays", pays.name.common, ". Error JSON:", JSON.stringify(err, null, 2));
       } else {
           console.log("PutItem succeeded:", pays.name.common);
       }
    });
});

Pero sigo recibiendo este error AQUÍ ¿Alguien tiene una idea sobre cómo solucionar este problema? Traté de seguir los mismos pasos en el sitio: ¿Crear tabla usando nodejs Dynamodb?

Pero no funciona.

Mi CreateTable.js

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

AWS.config.update({
  region: "us-west-2",
  endpoint: "http://localhost:8000"
});

var dynamodb = new AWS.DynamoDB();

var params = {
    TableName : "Pays",
    KeySchema: [       
        { AttributeName: "region", KeyType: "HASH"},  //Partition key
        { AttributeName: "name", KeyType: "RANGE" }  //Sort key
    ],
    AttributeDefinitions: [       
        { AttributeName: "region", AttributeType: "S" },
        { AttributeName: "name", AttributeType: "S" }
    ],
    ProvisionedThroughput: {       
        ReadCapacityUnits: 10, 
        WriteCapacityUnits: 10
    }
};

dynamodb.createTable(params, function(err, data) {
    if (err) {
        console.error("Unable to create table. Error JSON:", JSON.stringify(err, null, 2));
    } else {
        console.log("Created table. Table description JSON:", JSON.stringify(data, null, 2));
    }
});

Algunos datos :

[
    {
        "name": {
            "common": "Aruba",
            "official": "Aruba",
            "native": {
                "nld": {
                    "official": "Aruba",
                    "common": "Aruba"
                },
                "pap": {
                    "official": "Aruba",
                    "common": "Aruba"
                }
            }
        },
        "translations": {
            "ces": {
                "official": "Aruba",
                "common": "Aruba"
            },
            "deu": {
                "official": "Aruba",
                "common": "Aruba"
            },
            "jpn": {
                "official": "\u30a2\u30eb\u30d0",
                "common": "\u30a2\u30eb\u30d0"
            },
            "kor": {
                "official": "\uc544\ub8e8\ubc14",
                "common": "\uc544\ub8e8\ubc14"
            },
Answer
        "name": {
            "common": "Aruba",
            "official": "Aruba",
            "native": {
                "nld": {
                    "official": "Aruba",
                    "common": "Aruba"
                },
                "pap": {
                    "official": "Aruba",
                    "common": "Aruba"
                }
            }
        }

namees un objeto por lo que no puede pays.namecomo el valor de name, ya que es del tipo de datos "Cadena".

Para solucionar el problema, puede cambiar la definición de la tabla a:

var params = {
    TableName : "Pays",
    KeySchema: [       
        { AttributeName: "region", KeyType: "HASH"},  //Partition key
        { AttributeName: "name.common", KeyType: "RANGE" }  //Sort key
    ],
    AttributeDefinitions: [       
        { AttributeName: "region", AttributeType: "S" },
        { AttributeName: "name.common", AttributeType: "S" }
    ],
    ProvisionedThroughput: {       
        ReadCapacityUnits: 10, 
        WriteCapacityUnits: 10
    }
};
Nuevo colaborador
Kaustubh Khavnekar is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.