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

@literacyplanet/lambda_gulp_deploy

v2.0.6

Published

copy, configure, npm install, zip, test, upload gulp tasks for aws lambda

Downloads

7

Readme

##AWS Lambda Gulp Tasks

This is a set of gulp tasks that copy, configure, npm install, zip, test, upload gulp tasks for aws lambda. The main difference between these gulp tasks and others I have found is it allows you to run tasks against multiple lambda handlers at once.

Installation

Install @literacyplanet/lambda_gulp_deploy

npm install @literacyplanet/lambda_gulp_deploy --save-dev

Install gulp (global is optional)

npm install gulp -g

In your local gulpfile.js

// add to gulpfile.js
var gulp = require('gulp');
var tasks = require('@literacyplanet/lambda_gulp_deploy');

// pass along gulp reference to have tasks imported
tasks.init(gulp);

Gulp Options

  • --handlerPath prefix to match path. Defaults to ./lambda/handlers/
  • --dist path to dist dir. Defaults to ./lambda/dist/
  • --configsPath path to configs dir. Defaults to ./lambda/configs/
  • --match match packages using node-glob. It looks for [handlerPath]/[match]/package.json
  • --env adds env to name of lambda and uses env to lookup .env file in [configsPath]/config.env.[env]
  • --lambdaRole needed when creating new lambdas
  • --testTimeout defaults to 2000 (2 seconds)

aws credentials are looked up in your environment. Check the aws-sdk for info as to where the configs live (hint ~/.aws/credentials).

Deploy Example

gulp deploy --match=** --env=staging --lambdaRole=arn:aws:iam::xxxxxx:role/
  • Deletes the {dist}/{handler} dir
  • Copies all files (excluding node_modules, test, README.md, MakeFile) from handler folder to {dist}/{handler} folder
  • Runs npm install --production on {dist}/{handler} folder
  • Copies environment vars from {configsPath}/{handler}/.env.{env} to {dist}/{handler}/.env
  • Zips {dist}/{handler} directory to {dist}/{handler}.zip
  • Uploads zip file to Lambda service using the name from {handler}/package.json with an -environment prefix (eg. my_awsome_lambda_handler-staging). It uses the aws config located in {configsPath}/{handler}/aws.{env}.json to set the Role, Timeout, Handler, MemorySize and Region. If a command line arg is set, configs take precedence over these settings.
  • Creates/updates/deletes event sources using the config located in {configsPath}/{handler}/aws.{env}.json

aws.{env}.json Format

{
  "EventSources": [
    {
      "EventSourceArn": "arn:aws:dynamodb:us-east-1:xxxxxx:table/my_dynamo_table/stream/2015-12-03T01:01:02.357",
      "StartingPosition": "TRIM_HORIZON",
      "Enabled": true,
      "BatchSize": 1
    }
  ],
  "Role": "arn:aws:iam::xxxxxx:role/lambda_basic_execution",
  "Timeout": 300,
  "Handler": "index.handler",
  "MemorySize": 128,
  "Region": "us-east-1"
}

Test Example

gulp test --match=**
  • Deletes the {handler}/node_modules dir
  • Runs npm in handlers folder (no production flag)
  • Runs tests from handlers folder
  • Concatenates coverage reports into one file (coverage/lcov.info) to make lambdas appear to be one project

Independent tasks

Build & deploy

  • build-clean
  • copy-files
  • env
  • build-npm-install
  • zip
  • upload
  • link-event-sources

Running tests

  • test-clean
  • test-npm-install
  • run-test
  • concat-coverage-reports

Custom tasks

This module exports an eachPackage method that uses async.eachLimit to apply the task in parallel (up to limit). The eachPackage method calls back with a handler that has the following props on.

pkg the package.json as an object literal pkgPath the path to the handlers package.json srcDir the path to the handler destDir the path to packages destination

var gulp = require('gulp');
var tasks = require('@literacyplanet/lambda_gulp_deploy');

tasks.init(gulp);

gulp.task('my-custom-task', ['find-packages'], function(callback) {
  var limit = 5; // apply this task to 5 packages at once!
  tasks.eachPackage(limit, function iterator(handler, cb) {

    // do something with this package
    console.log(handler);

    // { pkg:
    //    { name: 'my_handler',
    //      version: '1.0.0',
    //      description: '',
    //      main: 'index.js',
    //      author: 'Tim Fairbrother',
    //      scripts:
    //       { test: 'node_modules/.bin/mocha --compilers js:babel/register',
    //         watch_test: 'node_modules/.bin/mocha -w --compilers js:babel/register',
    //         run: 'node_modules/.bin/babel index.js' },
    //      license: 'ISC',
    //      dependencies:
    //       { dotenv: '^1.2.0',
    //         moment: '^2.10.3' },
    //      devDependencies:
    //       { babel: '^5.6.14',
    //         'expect.js': '^0.3.1',
    //         mocha: '^2.2.4',
    //         nock: '^2.12.0',
    //         proxyquire: '^1.4.0',
    //         sinon: '^1.14.1' } },
    //   pkgPath: '/Users/timfairbrother/code/lambda/handlers/my_handler/package.json',
    //   srcDir: '/Users/timfairbrother/code/lambda/handlers/my_handler',
    //   destDir: 'dist/my_handler/' }

    // Call this when done!
    cb();
  }, callback);
});

To override the deploy or test tasks, use run-sequence to create a newly named task with the tasks in the order you choose.