dynamodb-timeseries

A simple wrapper to get/set time-series data from AWS DynamoDB.


License
ISC
Install
npm install dynamodb-timeseries@0.2.7

Documentation

DynamoDB Time Series

Usage

  1. Add this package to your package.json file:

     "dependencies": {
         ...
         "dynamodb-timeseries": "^0.0.1",
         ...
     }
    
  2. Add a require statement to your code:

     const DynamoDbTimeSeries = require('dynamodb-timeseries/dynamodb-time-series.js');
    
  3. Create an instance of the API that attaches to a DynamoDB table:

     const dbApiInstance = Object.create(DynamoDbTimeSeries).setOptions({tableName: 'your_table_name'});
    
  4. Write to the DynamoDB table:

     const putResult = await dbApiInstance.putEvent(timeSeriesUniqueId, 'testEvent', startTime, event);
    

See files test/*.js for specific examples.

Prerequisites

  • You must have access to AWS, including any credentials, IAM permissions, and region as required by the AWS SDK

Unit Tests

Prerequisites

  • Set environment variable AWS_DEFAULT_REGION
  • Make your AWS credentials available in file ~/.aws

Interactive Invocation

  1. Run Docker Compose:

     docker-compose run app  /bin/bash
    
  2. Navigate to the directory where the source code is located:

     cd /home/code       
    
  3. Run NPM install

     npm install
    
  4. Navigate to the test directory:

     cd test
    
  5. Run NPM install again (for the test directory)

     npm install
    
  6. Run the unit tests

     npm test *.js
    

Automated Invocation

  1. Set environment variable AWS_DEFAULT_REGION to your desired region:

     export AWS_DEFAULT_REGION=us-east-1
    
  2. Run script test.sh

     ./test.sh
    

You should see a transcipt that looks similar to the following:

$ ./test.sh
audited 19 packages in 0.644s
found 0 vulnerabilities

up to date in 10.89s

> dynamodb-timeseries-test@0.0.1 test /home/code/test
> node_modules/tape/bin/tape "dynamodb-time-series.js"

TAP version 13
# create dynamoDB table for all tests. Use random keys to make tests independent
ok 1 table name is the random string created before the tests start
ok 2 table is active
# put and get a time series event
ok 3 put result is an empty object?... okay aws
ok 4 one item put, one item queried
ok 5 user ID and type match what was queried
ok 6 event contents queried is same as was put
# delete test table
ok 7 Table was deleted because we got correct exception trying to wait for it to delete

1..7
# tests 7
# pass  7

# ok