npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dynamodb-timeseries

v0.2.7

Published

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

Downloads

8

Readme

DynamoDB Time Series

This module allows one to use a dynamodb table as a time-series database, allowing queries for time ranges, and allows keeping data from different sources in the same table.

Usage

  1. Add this package and if necessary, a peer dependency of the AWS SDK to your package.json file.
    Note that AWS Lambda does not require the inclusion of the AWS SDK, it does that for you.

     "dependencies": {
         ...
         "dynamodb-timeseries": "^0.1.00",
         "aws-sdk: "^2.x",
         ...
     }
  2. Add a require statement to your code:

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

     const tableName           = 'Your existing DynamoDB table name';
     const dbTimeSeriesOptions = {
         tableName: tableName,
         awsOptions: {
             credentials: {
                 accessKeyId:     'An access key ID, typically created by STS',
                 secretAccessKey: 'A secret access key, typically created by STS',
                 sessionToken:    'A session token, typically created by STS',
                 expiration:      'The credentials expiration, typically created by STS'
             }
         }
     };
     const dbApiInstance = Object.create(DynamoDbTimeSeries).setOptions(dbTimeSeriesOptions);
  4. Create an event that will be written to the DynamoDB table:

     const event = {
         foo: 'bar'
     };
  5. Write to the DynamoDB table:

     const userId        = 'Your user ID';
     const eventType     = 'Your event type';
     const epochTime     = new Date().getTime();
     await dbApiInstance.putEvent(userId, eventType, epochTime, event);

See files test/*.js for specific examples.

output format

[
  {
   // outer attributes are common no matter the manufacturer
   epochTimeMilliSec: ... per Javascript standard.  56 bit int or a 64 bit float ... ,
   mfgrId: '<ID of the manufacturer>'
   event: { ... event specific to the manufacturer, see their API ... },
  }
]

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
  • set environment variable export NPM_TOKEN=$(cat ~/.npm/token)
  • 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. Run the unit tests

     npm test 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

> [email protected] 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