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

lambda-bin

v0.0.1

Published

Add non-standard binaries to serverless compute.

Downloads

11

Readme

lambda-bin

NPM Version Build Status Codacy Badge Coverage Status Known Vulnerabilities FOSSA Status

Add non-standard binaries to serverless compute.

Overview

This module reduces the footprint of the run-time only part of the bin-minify module and adds a few AWS Lambda specific functions.

Still, this module's core functionality should work well for other serverless providers as well. Please open an issue if you come across limitations using this module with other serverless providers.

Install

$ npm install --save lambda-bin

Usage

const path = require('path');
const LambdaBin = require('lambda-bin');
const MY_LAMBDA_BIN_PATH = path.join('/', 'tmp', 'my_bin');

var myLambdaBin = new LambdaBin({
  targetPath: path.resolve(__dirname, path.join('bin', 'my_bin')),
  minPack: require('MY_MIN_PACK_FILE'),
});

myLambdaBin.applyMinPack(MY_LAMBDA_BIN_PATH).then((result) => {
  if (result.accepted) {
    // Setup the PATH environment variable
    myLambdaBin.setPath(MY_LAMBDA_BIN_PATH);
    // And maybe some other environment variables
    myLambdaBin.setEnv({
      ENV_VAR1: 'some value',
      ENV_VAR2: 'another value',
    }, true);
    // Or setup the PATH and other environment variables yourself...
  }
  // Binaries are ready to use
}, error => {
  throw new Error(`Binaries could not be correctly setup: ${error}`);
});

API

constructor (options)

Object new LambdaBin( Object )

options

  • Type: Object
  • Optional

The following are supported keys in the options JSON object. Any other keys are ignored.

targetPath
  • Type: string
  • Default: ./bin/bin-minify

Location of the actual binaries.

Note: Typically the binaries under targetPath are source controlled (and should be included in the npm module or Lambda package).

useSymlinks
  • Type: boolean

Any value passed will be replaced with false, which is required for bin-minify to work on AWS Lambda

minPack
  • Type: Object
  • Default: {}

Used to load a previously created minPack.

Note: A minPack is created using bin-minify stagingBin.createMinPack() and saved to a source controlled file (which should be included in the npm module or Lambda package).

Promise runtimeBin.applyMinPack (fromBase)

fromBase

  • Type: string
  • Required

Base path where the original file structure of the binaries will be recreated.

returns Promise

Resolved Promise: { loaded: true or false }. loaded will be:

  • true if the file structure was successfully created.
  • false if the fromBase path already existed.

Rejected Promise: { error }.

String setPath (pathsToAdd)

Once the original file structure of the binaries is recreated, it is necessary to add them to the PATH before the binaries can be invoked. setPath() can be used for this purpose.

pathsToAdd

  • Type: string or Array

The path(s) for the binaries. Typically these paths are children of fromBase and/or fromBase itself.

Note: These paths will be prepended to the system PATH.

returns String

The resulting PATH.

setEnv (variablesToSet, shouldOverwrite)

Some binaries rely on environment variables to control their behavior (e.g. NODE_PATH), or require existing environment variables to be updated (e.g. LD_LIBRARY_PATH). setEnv() can be used to setup environment variables.

variablesToSet

  • Type: Object

Key-values pairs representing the environment variables to add/change, where the key is the environment variable name and the value its associated value.

shouldOverwrite

  • Type: boolean

If true, any existing value will be replaced. If false the value provided will be appended to any existing value using ':'.

Tip: If it necessary to overwrite and append values, call setEnv() twice and change the value of shouldOverwrite accordingly.

AWS Lambda Limits

Please keep these AWS lambda limits in mind when deploying lambda functions.

License

MIT © BotBitsSM