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

aws-lambda-helper

v2.23.0

Published

Collection of helper methods for lambda

Downloads

51

Readme

aws-lambda-helper

Collection of helper methods for lambda

Build Status codecov.io Dependency Status devDependency Status

Installation

$ npm install aws-lambda-helper --save

Usage

  var AwsHelper = require('aws-lambda-helper');

  exports.handler = function(event, context) {
    ...
    //Initialise the helper by passing in the context
    AwsHelper.init(context);
    ...
  }

Invoke a Lamda function


  var AwsHelper = require('aws-lambda-helper');

  exports.handler = function(event, context){
    // assume : context.invokedFunctionArn = invokedFunctionArn: 'arn:aws:lambda:eu-west-1:123456789:function:mylambda:prod'

    //Initialise the helper by passing in the context
    AwsHelper.init(context);

    console.log(AwsHelper.env); //prints: prod
    console.log(AwsHelper.region); //prints: eu-west-1
    console.log(AwsHelper.account); //prints: 123456789

    var params = {
        FunctionName: 'MyAmazingLambda',
        Payload: { 'hello': 'world' },
        Qualifier: ''
      };
    AwsHelper.Lambda.invoke(params, function (err, data) {
      AwsHelper.failOnError(err, event, context);
      context.succeed(data);
    });
  }

Logging JSON messages

var AwsHelper = require('aws-lambda-helper');

exports.handler = function(event, context){
  // assume : context.invokedFunctionArn = invokedFunctionArn: 'arn:aws:lambda:eu-west-1:123456789:function:mylambda:prod'

  //Initialise the helper by passing in the context
  AwsHelper.init(context, event);

  var log = AwsHelper.Logger('example');

  log.info();     // Returns a boolean: is the "info" level enabled?
  // This is equivalent to `log.isInfoEnabled()` or
  // `log.isEnabledFor(INFO)` in log4j.

  log.info('hi');                     // Log a simple string message (or number).
  log.info('hi %s', bob, anotherVar); // Uses `util.format` for msg formatting.

  log.info({foo: 'bar'}, 'hi');
  // The first field can optionally be a "fields" object, which
  // is merged into the log record.

  log.info(err);  // Special case to log an `Error` instance to the record.
  // This adds an "err" field with exception details
  // (including the stack) and sets "msg" to the exception
  // message.
  log.info(err, 'more on this: %s', more);
  // ... or you can specify the "msg".

  log.info({foo: 'bar', err: err}, 'some msg about this error');
  // To pass in an Error *and* other fields, use the `err`
  // field name for the Error instance.
}

Pushing Data Back to Client(s) Via WebSocket Server

var params = {
  id: sessionId, // the id provided by the WebSocket Server AKA "connectionId"
  bucketId: 12345, // the id of this rticular search request
  userId: 'UniqueFingerprint', // the super long string that uniquely identifies a client
  items: [{  // your list of one or more tiles or packages go here
    url: '/userId/connectionId/bucketId/itemId', // url for S3 object.
  }] // note: url should not have .json in it.
};
AwsHelper.pushResultToClient(params, function (err, res) {
  console.log(err, res); // do what ever you want after the result is pushed
});

Retrieving a Search Result (Artile Tile or Package)

When a user shares a result tile (e.g. an article or package) we retrieve the result they saw from S3:

var params = {
  url: '/userId/connectionId/bucketId/itemId', // supplied by front-end
};
AwsHelper.getRecordFromS3(params, function (err, json) {
  console.log(err, json); // handle error or use json
});

Environment Variables

You will require an the following Environment Variables to push results to S3 and retrieve them later:

export WEBSOCKET_SERVER_URL=get_this_from_codeship
export AWS_S3_SEARCH_RESULT_BUCKET=get_this_from_codeship
export SEARCH_RESULT_TOPIC=arn:aws:sns:eu-west-1:123456789:my-awesome-topic

(see below for complete list of required Environment Variables)

if you get stuck get the Environment Variables from CodeShip: https://codeship.com/projects/143221/configure_environment