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.
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);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With