Git Product home page Git Product logo

dynamo-client's Introduction

This library is deprecated, use AWS's DocumentClient instead.

dynamo-client

Build Status

This is a low-level client for accessing DynamoDB from node.js. It offers a simpler and more node-friendly API than Amazon's SDK, in the style of @mikeal's popular request library.

Example

// assuming AWS credentials are available from process.ENV
var dynamo = require("dynamo-client")
  , region = "us-east-1"
  , db     = dynamo.createClient(region)

db.request("ListTables", null, function(err, data) {
  console.log(data.TableNames.length + " tables found.")
})

API

db = dynamo.createClient(region, [credentials])

This creates a database instance for the given DynamoDB region, which can be one of the following:

  • us-east-1 (Northern Virginia)
  • us-west-1 (Northern California)
  • us-west-2 (Oregon)
  • eu-west-1 (Ireland)
  • ap-northeast-1 (Tokyo)
  • ap-southeast-1 (Singapore)
  • ap-southeast-2 (Sydney)
  • sa-east-1 (Sao Paulo)

The official region list can be found in the AWS documentation.

You can also pass an object in here with host, port, region, version, and/or credentials parameters:

var db = dynamo.createClient({host: "localhost", port: 4567, version: "20111205"})

This is especially useful if you want to connect to a mock DynamoDB instance (such as FakeDynamo or ddbmock).

For backwards compatibility with versions <= 0.2.4, you can also pass the full host in here too (should detect most hostnames unless they're incredibly similar to an AWS region name):

var db = dynamo.createClient("dynamodb.eu-west-1.amazonaws.com")

Your AWS credentials (which can be found in your AWS console) can be specified in one of two ways:

  • As the second argument, like this:
dynamo.createClient("us-east-1", {
  secretAccessKey: "<your-secret-access-key>",
  accessKeyId: "<your-access-key-id>"
})
  • From process.env, such as like this:
export AWS_SECRET_ACCESS_KEY="<your-secret-access-key>"
export AWS_ACCESS_KEY_ID="<your-access-key-id>"

db.request(targetName, data, callback)

Database instances have only one method, request, which takes a target name, data object, and callback.

The target name can be any of the operations available for DynamoDB, which currently include the following:

  • BatchGetItem
  • BatchWriteItem
  • CreateTable
  • DeleteItem
  • DeleteTable
  • DescribeTable
  • GetItem
  • ListTables
  • PutItem
  • Query
  • Scan
  • UpdateItem
  • UpdateTable

The data object needs to serialize into the DynamoDB JSON format.

The callback is called with the usual (err, data) signature, in which data is an object parsed from the JSON returned by DynamoDB.

To match AWS expectations, the following requests are automatically retried with exponential backoff (50ms, 100ms, 200ms, 400ms, etc) upon failure:

  • 5xx errors
  • 400 ThrottlingException errors
  • 400 ProvisionedThroughputExceededException errors

Retries are attempted up to 10 times by default, but this amount can be changed by setting dynamo.Request.prototype.maxRetries to the desired number.

dynamo-client's People

Contributors

jed avatar mhart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dynamo-client's Issues

Thin wrapper?

Hi Jed

I'm a bit confused. By looking at the package.json dependencies and reading the README this seems to be a driver implementation from scratch, as opposed to a thin wrapper over Amazon's SDK.

Yet, you deprecated your https://github.com/jed/dynamo project a couple of years ago and adviced people into using Amazon's SDK.

Is there something I'm missing?
Thanks

error while parsing the chunk

Hi,

I an facing error response from dynamo-client while using query. The error response comes very often. But, sometimes I get a proper response also. So, its not a data issue. I get error in dynamo-client, when it parses the json response.

[2017-05-11 21:10:18:701] SyntaxError: Unexpected token S
at Object.parse (native)
at IncomingMessage. (/home/chenoa/Desktop/02-05-2017/v4api_07_20_16/v4api/node_modules/dynamo-client/dynamo_client.js:92:29)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:905:12)
at doNTCallback2 (node.js:441:9)
at process._tickDomainCallback (node.js:396:17)
[2017-05-11 21:10:18:702] Error while using query: SyntaxError: Unexpected token S
[2017-05-11 21:10:18:728] Error: HTTP/1.1 200

Is it that, response is yet not completed and the control moved to res.end method or is it something to do with concurrency.
The issue des not happen always but, it does happen very frequently.

Thanks.

Queue requests to the same table when exceeding throughput

I see an interesting phenomenon if I change the tests to use the ap-southeast-2 region, which is the closest region to me at the moment, whereby the concurrency/ProvisionedThroughputExceededException test takes around 50 seconds to complete - this is compared with around 10 secs or so for us-east-1, which I have a much higher latency to.

This is counter intuitive at first glance, but I think what is happening (yet to confirm) is that because the latency is so much lower for me to ap-southeast-2, the 50 parallel requests can be made a lot faster, and therefore they trigger the ProvisionedThroughputExceededException much sooner and end up in a cycle of contention as all 50 requests slowly back off.

What I'm thinking could be a good idea to attempt to reduce this contention would be to have a per-table queue or limit on how many parallel requests can be made (similar to https://github.com/caolan/async#queue) - perhaps this queue only starts getting used once ProvisionedThroughputExceededExceptions start getting thrown.

Thoughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.