I'm answering this question for myself and others because I found the AWS JS SDK V3 documentation and examples to be super annoying and misleading. The official SDK docs do not provide an example for showing marshaled output so you see a bunch of object types in your response. The DDB Doc client by default will remove those but they don't show you how. The answer I am posting gives you a marshaled response, meaning it cleans out the object type strings.
An example of an unmarshalled response is like this, notice the S for string as the value type.
[
{
project_name: { S: 'fake project' },
service_now_request_id: { S: 'CHG000212312' },
service_now_request_url: {
S: 'https://service-now.com/sampleApp?id=snx&spa=1&m=changes&r=0d12121aa442f33c8e0ebb3555'
}
}
]
If you want a response like below, you should use the full DDB document client:
[
{
project_name: 'fake project',
service_now_request_id: 'CHG000212312',
service_now_request_url: 'https://service-now.com/sampleApp?id=snx&spa=1&m=changes&r=0d12121aa442f33c8e0ebb3555',
}
]
Here's my sample code, feel free to nitpick or post a full ES6 version if you want.
const {DynamoDB} = require("@aws-sdk/client-dynamodb");
const { DynamoDBDocument } = require('@aws-sdk/lib-dynamodb');
const client = new DynamoDB({region: "us-west-2",});
const ddbDocClient = DynamoDBDocument.from(client);
async function marshaledScanOutput() {
const primaryDynamoDBTableName = "yourDDBTableName";
ddbParams = {TableName: primaryDynamoDBTableName};
try {
let testScan = await ddbDocClient.scan(ddbParams);
let result = [];
do {
testScan.Items.forEach((item) => result.push(item));
ddbParams.ExclusiveStartKey = testScan.LastEvaluatedKey;
} while (typeof testScan.LastEvaluatedKey != "undefined");
console.log(result);
// Example output:
// [
// {
// project_name: 'fake project',
// service_now_request_id: 'CHG000212312',
// service_now_request_url: 'https://service-now.com/sampleApp?id=snx&spa=1&m=changes&r=0d12121aa442f33c8e0ebb3555',
// }
// ]
}
catch(error) {
throw error;
}
}
marshaledScanOutput();