DynamoDB Client

SaltwaterC edited this page Jan 25, 2012 · 2 revisions

Client loader


Available low level method

dynamodb.request(operation, [json], callback)

The 'operation' argument is the operation required by the DynamoDB REST API itself.

The 'json' argument must be the the JSON Data Format in Amazon DynamoDB. You may pass a JS object that resembles a JSON structure. Internally JSON.stringify() is used before sending the data to the API.

The result argument of the passed callback contains the parsed JSON response. JSON.parse() is used internally, therefore it is a JavaScript object.

Please note that for the moment this client is just a thin wrapper over the DynamoDB API which takes care of most of the low level plumbing (such as request authentication). Common usage patterns may receive additional helper methods which can improve the usability of this client by wrapping the request method.

Available helpers


// init the STS client for getting the access credentials
var aws = require('aws2js');
var sts = require('sts', accessKeyId, secretAccessKey);

// init the DynamoDB client
var dynamodb = require('aws2js').load('dynamodb');

sts.request('GetSessionToken', function (err, res) {
	if (err) {
	} else {
		var credentials = res.GetSessionTokenResult.Credentials;
		dynamodb.setCredentials(credentials.AccessKeyId, credentials.SecretAccessKey, credentials.SessionToken);
		dynamodb.request('ListTables', function (err, res) {
			if (err) {
			} else {
				console.log('The tables are: ');


  • The DynamoDB API doesn't have region support.
  • Due to the fact that the DynamoDB must use the temporary credentials returned by the STS Client, the client can't be used directly. Hopefully the Amazon folks come to their senses and realize how uninspired it is to have temporary credentials for database access. Just for the sake of complexity and adding yet another point of failure in the stack. People who worked with AWS APIs for more than one day, should know what I'm talking about. I am not complaining about having STS support. Others APIs also have this. But they didn't make it mandatory. It is available as an option.
  • For the moment there's no implemented method for fetching the STS credentials. You may poll them after a timeout period, lazy load them and serialize the requests till a response is returned, etc. This doesn't mean that it won't be, but it is a thing that must be figured out.