API Docs for:
Show:

DynDB Class

Defined in: dyndb.js:14
Module: dyndb

DynDB Constructor. It accepts the AWS access keys and the AWS region. If no arguments are passed, it gets the keys and region from the following environment variables:

  1. AWS_ACCESS_KEY_ID
  2. AWS_SECRET_ACCESS_KEY
  3. AWS_REGION

Constructor

DynDB

(
  • [accessKeyID]
  • [secretAccessKey]
  • [region='us-east-1']
  • [securityToken]
)

Defined in dyndb.js:14

Parameters:

  • [accessKeyID] String optional

    Your AWS access key ID

  • [secretAccessKey] String optional

    Your AWS secret access key

  • [region='us-east-1'] String optional

    The AWS region you would like to use

  • [securityToken] String optional

    The security token

Methods

basicISODate

(
  • [date]
)
String private

Defined in dyndb.js:212

Generates an ISO8601 basic date string (YYYYMMDD'T'HHMMSS'Z') for the given date instance

Parameters:

  • [date] Date optional

    A date instance. If no date is given, a new Date() is used

Returns:

String: An ISO8601 basic date string

getEC2IAMRole

(
  • callback
)
private

Defined in dyndb.js:306

Gets the EC2 IAM role name from the metadata service.

Parameters:

  • callback Function

    Callback function that receives the role returned by the metadata service.

getEC2IAMSecurityCredentials

(
  • role
  • callback
)
private

Defined in dyndb.js:319

Gets the security credentials from the metadata service.

Parameters:

  • role String

    IAM role name.

  • callback Function

    Callback function that receives the parsed credentials object returned by the metadata service.

hmac

(
  • key
  • data
  • [encoding='binary']
)
Object private

Defined in dyndb.js:142

Uses Crypto.Hmac to calculate the SHA256 HMAC for the given data

Parameters:

  • key String

    The hmac key to be used

  • data String

    The data for which to calculate the HMAC

  • [encoding='binary'] String optional

    The desired output encoding for the HMAC. Can be 'hex', 'binary' or 'base64'

Returns:

Object: The calculated HMAC value. The type of the return value depends on the given encoding

httpRequest

(
  • options
  • body
  • [callback]
  • [useHttps=false]
)
private

Defined in dyndb.js:226

This is the method that send the actual HTTP requests, caches the response, and executes the callback after the response has been received.

Parameters:

  • options Object

    The HTTP options to use when sending the request.

  • body Buffer | String

    The request's body. Must be a Buffer or a String. Set it to null, undefined, false, or '' to send a request with no body (a GET request for instance).

  • [callback] Function optional

    Callback function to call after the response has been received.

  • [useHttps=false] Boolean optional

    Set this to true to use HTTPS.

needsToLoadEC2IAMRoleCredentials

() private

Defined in dyndb.js:340

Helper function that returns true if getting the security credentials from the metadata service is needed or false otherwise.

request

(
  • operationName
  • [body='{}']
  • [callback]
  • [context]
)
chainable

Defined in dyndb.js:352

Sends a request to Amazon DynamoDB

Parameters:

  • operationName String

    Name of the DynamoDB operation to request. Consult DynamoDB documentation for a list of available operations

  • [body='{}'] Object | String optional

    Body of the request to send. If it's not a string, it is converted into a string using JSON.stringify(). Consult DynamoDB documentation for details about the body for each type of operation

  • [callback] Function optional

    Callback function to execute after the response has been received or when an error was triggered during the request. The callback function should take the following arguments:

    • error Object

      This can be:

      1. The error object passed by the underlying http request if the 'error' event was triggered
      2. The response's status code, if it's not 200
      3. Exception object thrown by JSON.parse()
      4. Undefined if there was no error
    • json Object | String

      The parsed JSON response or a string if the response is not a valid JSON string

  • [context] Object optional

    The context in which the callback should be executed, meaning that whenever the callback function is called, the value of this, inside the callback, will be context. If no context is given, the value of this would be the underlying request's http.ClientResponse object, which contains data like statusCode and headers

sendRequest

(
  • operationName
  • [body='{}']
  • [callback]
  • [context=httpResponseObject]
)
private

Defined in dyndb.js:261

Underlying method that builds the request before sending it and relays the response to the callback.

Parameters:

  • operationName String

    Name of the DynamoDB operation to request.

  • [body='{}'] Object | String optional

    Body of the request.

  • [callback] Function optional

    Callback function to call after receiving the response.

  • [context=httpResponseObject] Object optional

    Context in which the callback should be executed. Defaults to the underlying HTTP response object.

setup

(
  • [accessKeyID]
  • [secretAccessKey]
  • [region='us-east-1']
  • [securityToken]
)
chainable

Defined in dyndb.js:118

Sets the access keys and region to use for every request. If no arguments are passed, it gets the keys and region from the following environment variables:

  1. AWS_ACCESS_KEY_ID
  2. AWS_SECRET_ACCESS_KEY
  3. AWS_REGION

Parameters:

  • [accessKeyID] String optional

    Your AWS access key ID

  • [secretAccessKey] String optional

    Your AWS secret access key

  • [region='us-east-1'] String optional

    The AWS region you would like to use

  • [securityToken] String optional

    The security token

sha256Hash

(
  • data
  • [dataEncoding='binary']
  • [encoding='hex']
)
Object private

Defined in dyndb.js:158

Uses Crypto.Hash to calculate the SHA256 hash for the given data

Parameters:

  • data String

    The data from which to calculate the hash

  • [dataEncoding='binary'] String optional

    The data's encoding. Can be 'utf8', 'ascii' or 'binary'

  • [encoding='hex'] String optional

    The desired output encoding for the hash. Can be 'hex', 'binary' or 'base64'

Returns:

Object: The calculated hash value. The type of the return value depends on the given encoding

signRequest

(
  • httpOpts
  • body
)
private

Defined in dyndb.js:174

Signs a given request. Follows the AWS signature v4 specs to add the Authorization header in httpOpts

Parameters:

  • httpOpts Object

    The http options object that will be used when calling the https.request() method

  • body Buffer

    The Buffer instance of the request body

Properties

accessKey

String private

Defined in dyndb.js:82

AWS Access Key ID.

API_VERSION

String private final

Defined in dyndb.js:41

DynamoDB's API version used in the HTTP headers of every request

credentialsExpiration

Date private

Defined in dyndb.js:109

Expiration date of the current credentials obtained from the EC2 metadata service.

EC2_METADATA_HOST

String private final

Defined in dyndb.js:51

IP address of the EC2 metadata service.

region

String private

Defined in dyndb.js:73

AWS region.

secretKey

String private

Defined in dyndb.js:91

AWS Secret Access Key.

SECURITY_CREDENTIALS_RESOURCE

String private final

Defined in dyndb.js:61

Path to the security-credentials within the EC2 metadata service.

securityToken

String private

Defined in dyndb.js:100

AWS Security Token, used only when the credentials come from the EC2 metadata service.

SERVICE_NAME

String private final

Defined in dyndb.js:31

DynamoDB's service name used in the HTTP headers and to create the signature that authenticates every request