8

All - I am working on a specific business requirement and with the lack of info on Google I thought I would stop here for some info:

I am basically ingesting a CSV, converting it to a JSON Object and stuffing it into Dynamo. The interesting part is, the data types of the row values jump between strings and numbers but I am unable to get this to work properly.

I am using Node and the aws-sdk and literally used the Amazon Docs to test this straight up and it still did not work, see below:

var params = {
    TableName: foo,
    Item: {
        masterReportsUuid: uuidv4(),
        reportDate: _eventDate,
        "testAttribute": {
            "Name": {
                "S": "Joe"
            },
            "Age": {
                "N": "35"
            }
        },
    }
};



dbDocClient.put(params, (err, data) => {
    if (err) {
        //log to CloudWatch
        console.log(err);
        reject(err);
    } else {
        resolve(data);
    }
});

The testAttribute obviously is a Map with Name and Age, string and number. This is straight from the documentation -

https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#putItem-property

An attribute of type Map. For example:

"M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}}

But this outputs like this in Dynamo -

Dynamo Output

So my question is - why is this not working?

EDIT: Typos.

1 Answer 1

10

Ugh - I fixed the issue. I will leave this here in case anyone runs into this.

Two Issues - I was using the DynamoDB.DoucmentClient().put API Call and not the DynamoDB.putItem call AND my params object was close but not correct. Please see below for a working example of nested Map AttributeTypes -

const dbDocClient = new aws.DynamoDB.DocumentClient();
const dbDynamo = new aws.DynamoDB();

var params = {
    TableName: _ReportsTable,
    Item: {
        testUuid: {
            "S": uuidv4()
        },
        testDate: {
            "S": _eventDate
        },
        testAttribute: {
            "M": {
                "Name": {
                    "S": "Joe"
                },
                "Age": {
                    "N": "35"
                }
            }
        },
    }
};


dbDynamo.putItem(params, (err, data) => {
    if (err) {
        //log to CloudWatch
        console.log(err);
        reject(err);
    } else {
        resolve(data);
    }
});
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.