GithubHelp home page GithubHelp logo

ddbhelper's Introduction

You made me do this, Bezos.

Usage

Create a test event in the AWS console with either a queryParams or a scanParams field containing the AWS parameters to feed into the query or scan operation. If both fields exist, the query will be used and the scan will be ignored.

Optionally, a dataHandler field may also be defined in the test event. The value of this field must be a stringified javascript function that takes a single data parameter. If the scan or query succeeds, the results will be passed into the dataHandler function. If the dataHandler function returns any results, they will be returned in the lambda response. The default dataHandler simply returns the results of the DynamoDB operation.

Note: because this is a JSON string, it cannot contain newlines and must be flattened to a single line (an example of this is shown below).

Example:

{
  "queryParams": {
    "TableName": "gogo-dash-int-persist-dev-aircraftevents",
    "KeyConditionExpression": "#P = :pvalue AND begins_with(#S, :svalue)",
    "FilterExpression": "attribute_exists(CONSOLE)",
    "ExpressionAttributeNames": {
      "#P": "aircraftSID",
      "#S": "eventKey"
    },
    "ExpressionAttributeValues": {
      ":pvalue": "001F0000010HrN5IAK:a01F000000F2UBPIA3",
      ":svalue": "15913"
    }
  },
  "dataHandler": "data => {return data.Items.reduce((acc, item) => {if (item.CONSOLE.flight_state === 'ABOVE_SERVICE_ALTITUDE') {acc.ASA++} else {acc.BSA++}return acc},{ ASA: 0, BSA: 0 })}"
}

This sample test event will query the gogo-dash-int-persist-dev-aircraftevents table for records with

  • A partition key matching 001F0000010HrN5IAK:a01F000000F2UBPIA3
  • A sort key beginning with 15913
  • A defined CONSOLE field

If matching records are found, the dataHandler function will count and return the number of records whose CONSOLE.flight_state is or is not ABOVE_SERVICE_ALTITUDE.

The result of running the lambda with this test event would look something like this:

{
  "ASA": 26,
  "BSA": 5
}

Here is the same dataHandler before flattening:

data => {
  return data.Items.reduce(
    (acc, item) => {
      if (item.CONSOLE.flight_state === 'ABOVE_SERVICE_ALTITUDE') {
        acc.ASA++
      } else {
        acc.BSA++
      }
      return acc
    },
    { ASA: 0, BSA: 0 }
  )
}

ddbhelper's People

Contributors

mschleskegogo avatar

Watchers

 avatar

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.