Skip to content

Instantly share code, notes, and snippets.

@peteristhegreat
Last active January 5, 2023 21:04
Show Gist options
  • Save peteristhegreat/fee5278f16095ee6ee816d0cc4f1f571 to your computer and use it in GitHub Desktop.
Save peteristhegreat/fee5278f16095ee6ee816d0cc4f1f571 to your computer and use it in GitHub Desktop.
Unmarshall DynamoDb output, command line node script, aws cli, scan, get-item
#!/usr/bin/env node
// npm init
// npm install aws-sdk
// or npm install -g aws-sdk
// Usage:
// ./unmarshall.js '[{"H": {"S": "Hi"}}]'
// or
// ./unmarshall.jl "$(aws dynamodb scan --table-name "$table_name" --output json | jq -r '.Items')"
const AWS = require("aws-sdk");
var arguments = process.argv ;
// console.log(arguments) ; // 0th is node, 1st is the scriptname
var json_in = JSON.parse(arguments[2])
if (Array.isArray(json_in)){
json_in.forEach((v) => console.log(AWS.DynamoDB.Converter.unmarshall(v)))
} else {
console.log(AWS.DynamoDB.Converter.unmarshall(json_in))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment