4

I am using DynamoDB local and can create and delete table. I created a table with only one key like below

const tablePromise = dynamodb.listTables({})
    .promise()
    .then((data) => {
        const exists = data.TableNames
            .filter(name => {
                return name === tableNameLogin;
            })
            .length > 0;
        if (exists) {
            return Promise.resolve();
        }
        else {
            const params = {
                TableName: tableNameLogin,
                KeySchema: [
                    { AttributeName: "email", KeyType: "HASH"},  //Partition key

                ],
                AttributeDefinitions: [
                    { AttributeName: "email", 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));
              }
            });
        }
    });

Now I want to insert an item in the table following example doc at AWS.

var docClient = new AWS.DynamoDB.DocumentClient();
var tableNameLogin = "Login"
var emailLogin = "[email protected]";

var params = {
    TableName:tableNameLogin,
    Item:{
        "email": emailLogin,
        "info":{
            "password": "08083928"
        }
    }
};

docClient.put(params, function(err, data) {
    if (err) {
        console.error("Unable to add item. Error JSON:", JSON.stringify(err, null, 2));

    } else {
        console.log("Added item:", JSON.stringify(data, null, 2));
    }
});

When I run the insert item code, I get Added item: {} Why does it output an empty object? Is it actually inserting anything? I looked into this callback example but this time it doesn't output anything.

1 Answer 1

4

You need to add ReturnValues: 'ALL_OLD' to your put params. It will look like as mentioned below.

var params = {
    TableName:tableNameLogin,
    Item:{
        "email": emailLogin,
        "info":{
            "password": "08083928"
        }
    },
    ReturnValues: 'ALL_OLD'
};

For more details, you can follow this https://github.com/aws/aws-sdk-js/issues/803

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.