GithubHelp home page GithubHelp logo

dynamodb-touch's Introduction

dynamodb-touch

Build Status

Simulated DynamoDB Stream events based on the contents of a DynamoDB table.

What it does

Performs either a GetItem, Query, or Scan operation on a DynamoDB table, then passes each resulting record into a Kinesis stream in a wrapper identical to what would be provided by a DynamoDB stream INSERT event.

How to use it

You must provide your own configured Dyno and Kinesis clients. The Kinesis client must be pre-configured to provide the stream name with each request.

var touch = require('dynamodb-touch');
var AWS = require('aws-sdk');
var Dyno = require('dyno');

var clients = {
  dyno: Dyno({
    table: 'my-dynamodb-table',
    region: 'us-east-1'
  }),
  kinesis: new AWS.Kinesis({
    region: 'us-east-1',
    params: { StreamName: 'my-kinesis-stream' }
  })
};

// send one event for a dynamodb record with the provided key
touch.one({ id: 'some-record' }, clients, function(err) {
  if (err) throw err;
});

// query dynmodb, sending events for each result
touch.some({
  KeyConditions: {
    id: {
      ComparisonOperator: 'EQ',
      AttributeValueList: ['some-record']
    }
  }
}, clients, function(err) {
  if (err) throw err;
});

// scan every record in dynamodb, sending events for each result
touch.every(clients, function(err) {
  if (err) throw err;
});

// send one event for a feature that has already been fetched
var item = { id: 'record-id', data: 'record-data' };
touch.thisOne(item, clients, function(err) {
  if (err) throw err;
});

What events in Kinesis will look like

A Kinesis event will contain a Data property. For dynamodb-touch events, this will be a base64-encoded JSON string which mimics a DynamoDB Stream event.

kinesis.getRecords({ ShardIterator: 'xyz' }, function(err, data) {
  var record = data.Records[0];
  var dynamodbEvent = JSON.parse((new Buffer(record.Data, 'base64')).toString());
  console.log(JSON.stringify(dynamodbEvent, null, 2));
});

... will console.log:

{
  "eventId": "0",
  "eventVersion": "1.0",
  "awsRegion": "us-east-1",
  "eventSourceARN": "arn:aws:dynamodb:us-east-1:000000000000:table/my-dynamodb-table/dynamodb-touch",
  "eventSource": "dynamodb-touch",
  "eventName": "INSERT",
  "dynamodb": {
    "Keys": {
      "id": { "S": "my-record" }
    },
    "NewImage": {
      "id": { "S": "my-record" },
      "data": { "B": "aGVsbG8geW91" }
    },
    "StreamViewType": "NEW_IMAGE",
    "SequenceNumber": "0",
    "SizeBytes": 52
  }
}

dynamodb-touch's People

Contributors

rclark avatar tmcw avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dynamodb-touch's Issues

Framing this project

To frame the concept: we want a function to which you provide:

  • a kinesis stream ARN that you can kinesis:PutRecords to
  • a dynamodb table ARN that you can dynamodb:Scan

This module exposes this function, which scans the DynamoDB table and builds a mock DynamoDB stream record. Here's documentation on the structure of these records. The function writes a record into the kinesis stream for each item in the DynamoDB table.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.