DynDB Class
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:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_REGION
Constructor
DynDB
-
[accessKeyID] -
[secretAccessKey] -
[region='us-east-1'] -
[securityToken]
Parameters:
-
[accessKeyID]String optionalYour AWS access key ID
-
[secretAccessKey]String optionalYour AWS secret access key
-
[region='us-east-1']String optionalThe AWS region you would like to use
-
[securityToken]String optionalThe security token
Item Index
Methods
Methods
basicISODate
-
[date]
Generates an ISO8601 basic date string (YYYYMMDD'T'HHMMSS'Z') for the given date instance
Parameters:
-
[date]Date optionalA date instance. If no date is given, a
new Date()is used
Returns:
getEC2IAMRole
-
callback
Gets the EC2 IAM role name from the metadata service.
Parameters:
-
callbackFunctionCallback function that receives the role returned by the metadata service.
getEC2IAMSecurityCredentials
-
role -
callback
Gets the security credentials from the metadata service.
Parameters:
-
roleStringIAM role name.
-
callbackFunctionCallback function that receives the parsed credentials object returned by the metadata service.
hmac
-
key -
data -
[encoding='binary']
Uses Crypto.Hmac to calculate the SHA256 HMAC for the given data
Parameters:
-
keyStringThe hmac key to be used
-
dataStringThe data for which to calculate the HMAC
-
[encoding='binary']String optionalThe desired output encoding for the HMAC. Can be
'hex','binary'or'base64'
Returns:
encoding
httpRequest
-
options -
body -
[callback] -
[useHttps=false]
This is the method that send the actual HTTP requests, caches the response, and executes the callback after the response has been received.
Parameters:
-
optionsObjectThe HTTP options to use when sending the request.
-
bodyBuffer | StringThe request's body. Must be a Buffer or a String. Set it to
null,undefined,false, or''to send a request with no body (aGETrequest for instance). -
[callback]Function optionalCallback function to call after the response has been received.
-
[useHttps=false]Boolean optionalSet this to true to use HTTPS.
needsToLoadEC2IAMRoleCredentials
()
private
Helper function that returns true if getting the security credentials from the metadata service is needed or false otherwise.
request
-
operationName -
[body='{}'] -
[callback] -
[context]
Sends a request to Amazon DynamoDB
Parameters:
-
operationNameStringName of the DynamoDB operation to request. Consult DynamoDB documentation for a list of available operations
-
[body='{}']Object | String optionalBody 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 optionalCallback 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:
-
errorObjectThis can be:
- The error object passed by the underlying http request if the 'error' event was triggered
- The response's status code, if it's not
200 - Exception object thrown by
JSON.parse() - Undefined if there was no error
-
jsonObject | StringThe parsed JSON response or a string if the response is not a valid JSON string
-
-
[context]Object optionalThe
contextin which the callback should be executed, meaning that whenever the callback function is called, the value ofthis, inside the callback, will becontext. If nocontextis given, the value ofthiswould be the underlying request's http.ClientResponse object, which contains data likestatusCodeandheaders
sendRequest
-
operationName -
[body='{}'] -
[callback] -
[context=httpResponseObject]
Underlying method that builds the request before sending it and relays the response to the callback.
Parameters:
-
operationNameStringName of the DynamoDB operation to request.
-
[body='{}']Object | String optionalBody of the request.
-
[callback]Function optionalCallback function to call after receiving the response.
-
[context=httpResponseObject]Object optionalContext in which the callback should be executed. Defaults to the underlying HTTP response object.
setup
-
[accessKeyID] -
[secretAccessKey] -
[region='us-east-1'] -
[securityToken]
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:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_REGION
Parameters:
-
[accessKeyID]String optionalYour AWS access key ID
-
[secretAccessKey]String optionalYour AWS secret access key
-
[region='us-east-1']String optionalThe AWS region you would like to use
-
[securityToken]String optionalThe security token
sha256Hash
-
data -
[dataEncoding='binary'] -
[encoding='hex']
Uses Crypto.Hash to calculate the SHA256 hash for the given data
Parameters:
-
dataStringThe data from which to calculate the hash
-
[dataEncoding='binary']String optionalThe data's encoding. Can be
'utf8','ascii'or'binary' -
[encoding='hex']String optionalThe desired output encoding for the hash. Can be
'hex','binary'or'base64'
Returns:
encoding
signRequest
-
httpOpts -
body
Signs a given request. Follows the AWS signature v4
specs to add the Authorization header in httpOpts
Parameters:
-
httpOptsObjectThe http options object that will be used when calling the
https.request()method -
bodyBufferThe
Bufferinstance of the request body
Properties
accessKey
String
private
AWS Access Key ID.
API_VERSION
String
private
final
DynamoDB's API version used in the HTTP headers of every request
credentialsExpiration
Date
private
Expiration date of the current credentials obtained from the EC2 metadata service.
EC2_METADATA_HOST
String
private
final
IP address of the EC2 metadata service.
region
String
private
AWS region.
secretKey
String
private
AWS Secret Access Key.
SECURITY_CREDENTIALS_RESOURCE
String
private
final
Path to the security-credentials within the EC2 metadata service.
securityToken
String
private
AWS Security Token, used only when the credentials come from the EC2 metadata service.
SERVICE_NAME
String
private
final
DynamoDB's service name used in the HTTP headers and to create the signature that authenticates every request
