// assuming AWS credentials are available from process.ENVvar dynamo =region = "us-east-1"db = dynamodb
db = dynamo.createClient(region, [credentials])
This creates a database instance for the given DynamoDB region, which can be one of the following:
The official region list can be found in the AWS documentation.
You can also pass an object in here with
var db = dynamo
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
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:
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:
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.