I have a DynamoDB table that has an Item that is as follows:
{
"Item": {
"myPrimaryKey": {
"S": "config"
},
"mySecondaryKey": {
"S": "sports"
},
"configValues": {
"SS": [
"baseball",
"basketball",
"football"
]
}
}
}
I am running the following code, based on the documentation presented in the npm repository:
const { DynamoDB } = require('@aws-sdk/client-dynamodb');
const client = new DynamoDB({ region: 'us-east-1' });
const { DynamoDBDocument, GetCommand } = require('@aws-sdk/lib-dynamodb');
const ddbDocClient = DynamoDBDocument.from(client);
const params = {
'TableName': 'mySportBookTable',
'Key': {
'myPrimaryKey': 'config',
'mySecondaryKey': 'sports',
},
};
const data = await ddbDocClient.send(new GetCommand(params));
console.log('sendDocClientCommand -- Received data: ', JSON.stringify(data));
When inspecting data
, the nested attribute configValues
is represented as {}
and is empty. However, when I run the equivalent CLI command, the data is properly shown.
$ aws dynamodb get-item \
--table-name "mySportBookTable" \
--key '{"myPrimaryKey":{"S":"config"},"mySecondaryKey":{"S":"sports"}}'
{
"Item": {
"myPrimaryKey": {
"S": "config"
},
"mySecondaryKey": {
"S": "sports"
},
"configValues": {
"SS": [
"baseball",
"basketball",
"football"
]
}
}
}
This could be a simple configuration option but I can't seem to find any documentation that expands nested lists. In fact, all documentation I've come across states that unless ProjectionAttributes
is provided, all values are returned.
I'm using version 3.454.0 of the SDK.
I decided to inspect the lib-dynamodb library to see how the marshalling and unmarshalling was done. This brought me to the util-dynamodb
library.
It turns out that SS
types (string set) are unmarshalled as Sets which cannot be expressed via JSON.stringify
and must be accessed via it's methods such as has()
and entries()
.
The documentation doesn't make it clear that javascript type Arrays are converted to DynamoDB Lists either.