Skip to content
Switch branches/tags
This branch is up to date with master.

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Build Status Dependency Status devDependency Status

Dynamise wraps the native DynamoDB methods from aws-sdk for node.js in promisifed versions and also provides some sugar syntax to interact with your database.

Examples: Look into the example folder to learn about the available functions

API Docs

All the following examples assume that you got a client for a specific endpoint, like so:

var db = require("dynamise");
var client = db(endpoint);

Most of the methods, unless stated otherwise, return native ES6 Promises. See MDN for details.

  1. Table operations
  1. Item operations
  1. Others


Return the actual endpoint

var endpoint = client.endpoint();


{ protocol: 'http:',
  host: 'localhost:8000',
  port: 8000,
  hostname: 'localhost',
  pathname: '/',
  path: '/',
  href: 'http://localhost:8000/',
  title: 'local' }


You will get an array with all the table names associated with the endpoint.

  .then(function (res) {
    console.log(res.TableNames); // ['TableOne', 'TableTwo', 'TableThree']

See DynamoDB.listTables for more information.


Adds a new table to the database. If you have set(tableDefintion) a table definition already, you can use the tableName as a String parameter. Otherwise you are able to hand over a complete table object.


var tableDefinition = {
    // complete table definition


// or
client.set({tableName: tableDefinition});

Note: create() waits for the table to be in an ACTIVE state.

See DynamoDB.createTable for more information."tableName")

You will get certain information about the table specified."TableOne")
  .then(function (res) {

You response might look like this:

{ AttributeDefinitions:
   [ { AttributeName: 'id', AttributeType: 'S' }, ... ],
  TableName: 'TableOne',
   { ... },
   [ { AttributeName: 'id', KeyType: 'HASH' } ],
  CreationDateTime: Wed Jun 10 2015 16:47:24 GMT+0200 (CEST),
  ItemCount: 0,
  TableSizeBytes: 0,
  TableStatus: 'ACTIVE' }

See DynamoDB.describeTable for more information.

Returns information about the table, including the current status of the table, when it was created, the primary key schema, and any indexes on the table.


Deletes the table and all of its items.

// Assume "TableOne" exists
 .then(function (res) {
   // res contains a TableDescription object
   // res.TableStatus === 'DELETING'

See DynamoDB.deleteTable for mor information.


This function uses but only fetches the following information:

  • TableSizeBytes (total size in bytes)
  • ItemCount (number of items)

and if the table is upgradable (true|false).

  .then(function (res) {
    // do something with res
  .catch(function (err) {
    // throws a ResourceNotFoundException if table does not exist

A response object might look like this:

{ TableSizeBytes: 0,
  TableStatus: 'ACTIVE',
  ItemCount: 0,
  Upgradable: false }"tableName")

Checks if the table state is ACTIVE and returns an object with table data. If the table is not active it waits for the table to become active."TableOne")
  .then(function (res) {
    if (res.TableName === "TableOne") {
      console.log("You got the right table!");

Your response object might look like this:

{ AttributeDefinitions:
   [ { AttributeName: 'id', AttributeType: 'S' },
  TableName: 'Example',
   { ... },
   [ { AttributeName: 'id', KeyType: 'HASH' } ],
  CreationDateTime: Thu Jun 11 2015 15:31:42 GMT+0200 (CEST),
  ItemCount: 0,
  TableSizeBytes: 0,
  TableStatus: 'ACTIVE' }

Uses and therefore DynamoDB.describeTable.


Update the Provisioned Throughput for the given table. You are also able to add and/or update global secondary indexes.

See DynamoDB.updateTable


Recreates the table if exists or creates the table if not and waits until active.


Does an multiUpsert on the tables specified in the tables object. The param tables should look like

var tables = {
  "TableA": [item1, item2, ...],
  "TableB": [item1, item2, ...]

See DynamoDB.batchWriteItem for more information.


Returns an object with a TableName attribute containing an array with all read items.

var params = {
  RequestItems: {
    Example:{ // TableName
        {id:"1", email:""},
        {id:"1", FileId:""},
        // ...

  .then(function (resItems) {
    // do something

See DynamoDB.batchGetItem for more information.


client.table("Example").read("1", "")
  .then(function (resItem) {
    if(!resItem) {
      // there is no such item
    // do something with the item

Returns an item with the given hash and range (primary key). If there exists no such item in the database, nothing will be returned.

See DynamoDB.getItem.


With patch() you can do the following operations on your item:

  • Add new attributes
  • Delete attributes
  • Update attributes
// the following item does already exist in the database
var item = {
  id: "1", // hash
  email: "",
  name: "markus",
  points: "3",
  role: "user"

  id: "1",  // hash and/or range keys cannot be updated
  points: null, // will be removed
  role: "admin", // will be updated
  rule: "user-management" // will be added

See DynamoDB.updateItem for more information.


var item = {id: "1", email: ""};


Creates a new item. If the item already exists, it will be fully replaced.

See DynamoDB.putItem for more information.


Uses the batchWriteItem method from AWS.DynamoDB to do an upsert on many items. Note that batchWriteItem cannot update items. Items which already exist are fully replaced.

var items = [
  { UserId: "1", FileId: "file#1" },
  { UserId: "2", FileId" "file#2" },


NOTE: If you want to multiUpsert on different tables use the client.multiUpsert() method. Actually, this method is using it either.

See DynamoDB.batchWriteItem for more information.


Upload an array of items using multiUpsert. Returns a Promise which handles the events internally.

var items = [
  { UserId: "1", FileId: "file#1" },
  { UserId: "2", FileId" "file#2" },


NOTE: Currently this is only an alias for client.table("tableName").multiUpsert()


Returns an instance of UploadStream to handle an upload via stream manually.

There are mainly two possible scenarios to use the UploadStream

  1. download one whole table from a database and upload it to another database
  2. upload data from a JSON file

Use DownloadStream to upload data to another database using UploadStream

var downloadStream = client.table("TableOne").createDownloadStream();
var uploadStream = client.table("TableTwo").createUploadStream();


uploadStream.on("finish", function () {
  console.log("finished uploading items");

uploadStream.on("error", function (err) {

Upoad data from a JSON file using UploadStream

In this case you will need JSONStream to pipe data accordingly to UploadStream.

var fs = require("fs");
var path = require("path");
var jsonStream = require("JSONStream").parse("*");
var uploadStream = client.table("Example").createUploadStream();

// Read data from a file using fs.createReadStream()
var jsonFileStream = fs.createReadStream(path.resolve(__dirname, "data.json"));

// And now pipe anything to uploadStream

uploadStream.on("finish", function () {
  console.log("finished uploading items");

uploadStream.on("error", function (err) {


Actually this is an alias for client.table(tableName).scanAll() - does a complete scan.


Returns an instance of DownloadStream to handle a download manually.

var download = client.table("TableOne").createDownloadStream();
var downloadedItems = [];

download.on("data", function (chunk) {

download.on("end", function () {
  console.log("finished downloading " + downloadedItems.length + " items");

download.on("error", console.error);


Deletes a single item in a table.

See DynamoDB.deleteItem for more information.


Used to find items based on conditions.

      .find(params) // params is optional
      .where("UserId").equals("1") // hash key

You are able to pass a params Object to find() with attributes defined in DynamoDB.query. We build some sugar functions to make this even easier.

IMPORTANT NOTICE: If you pass KeyConditions make sure you are using the correct signature related to dynamodb-doc Condition Object. You have to hand over an array containing condition objects as described in the link above.

- index()

The same as params would include { IndexName: "IndexNameValue" }.


- all()

DynamoDB has several limitations related to how big a query response can be (more information about limitations can be found here). Thus we provide a all() method which handles the pagination for you.

Otherwise you would have to evaluate responses LastEvaluatedKey attribute youself.


- where()

This is used to define a hash key where a certain equals() condition is applied to.


Note: On hash keys you are only allowed to perform an equals() condition.

- and()

This is used to define a range key where a certain condition is applied to.


You are also allowed to apply the following conditions:

  • lt() - lower than
  • le() - lower than or equal
  • gt() - greater than
  • ge() - greater than or equal
  • between()
  • beginsWith()


var params = {
	TableName: "TableOne",
	KeyConditions: [
		client.Condition("id", "EQ", "1")

	.then(function (res) {
	  // do something with your query

Your response is an array with all items which fit your query conditions.

To know more about a params object, please look at DynamoDB.query.


Returns items of a table.

If the total number of scanned items exceeds the maximum data set size limit of 1 MB, the scan stops and results are returned to the user as a LastEvaluatedKey value to continue the scan in a subsequent operation.

  .then(function (res) {
    // do something with the items

Your response object might look like this:

{ Count: 8467,
  ScannedCount: 8467,
  Items: [ ... ], // array with 8467 items
  // LastEvaluatedKey:

This method is helpful in case of pagination. Look at the following example:

var limit = 10;
client.table(tableName).scan({Limit: limit})
  .then(function (res) {
    // process res.Items

    // are there still more items to fetch?
    if (res.LastEvaluatedKey) {
      console.log("There are still more items to fetch...");

      // build a new query with LastEvaluatedKey
      params = {
        Limit: 10,
        ExclusiveStartKey: res.LastEvalutedKey

      // Now use this params object to query the next 10 items with scan(params)

Note: This is a very basic and simple example. You would write methods like next() to fetch the next x items and use it in a loop or wait for a user to query the next items. There is a more complex example in the example/ directory.

See DynamoDB.scan for more information.


Uses client.table("tableName").scan() to scan all items of a table. You will get an array with all items of a table.

  .then(function (res) {
    console.log(res.length) // number of items

Error Reporting

A small note on error reporting: Please make sure to always use a .catch() block when working with the API, otherwise you might miss some errors.

  .catch(function (err) {
    // log error, for example
    // console.trace(err.stack)

DynamoDB methods

Additionally we expose the underlying promisified methods to access the native DynamoDB methods.

return client.dynamo.getItem(params);
// return client.dynamo.batchWriteItem(params);



The promised DynamoDB client of your dreams



No releases published


No packages published