Skip to content
Intelligently prepare Node.js Lambda functions for deployment
Branch: master
Clone or download
Latest commit f2f6775 Apr 22, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Add missing project files. Jan 30, 2019
src
.eslintrc.json Add eslint testing step Apr 20, 2019
.gitignore Add some basic unit tests Apr 22, 2019
.prettierrc.json use blank prettier Apr 4, 2019
.travis.yml Fix missing dependency resolve and add a dep test Feb 20, 2019
CHANGELOG.md 0.3.1 Apr 22, 2019
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE Add missing project files. Jan 30, 2019
README.md
bin.js Dont zip go functions Mar 28, 2019
index.js remove serve and dependencies Apr 16, 2019
package.json 0.3.1 Apr 22, 2019

README.md

zip-it-and-ship-it

npm version build status dependencies downloads

This module handles zipping up lambda functions with their dependencies before deployment. You are probably looking for netlify-cli or js-client.

Installation

npm install zip-it-and-ship-it

Usage

const { zipFunctions } = require("@netlify/zip-it-and-ship-it");

zipFunctions("functions", "functions-dist");

This will take all functions in the functions folder and create a matching .zip file in the functions-dist folder.

Each function can either be a single .js file that exports a handler or a folder with a .js with the same name as the folder exporting a handler.

The packaging tool will look for the package.json closest to the handler and use that for dependency resolution. Make sure you've run npm install or yarn for each package.json before using zip-it-and-ship-it.

Ie, the following combinations would all work:

/functions/foo.js
/package.json
/node_modules/
/functions/foo.js
/functions/bar/bar.js
/functions/package.json
/functions/node_modules/
/functions/foo.js
/functions/bar/bar.js
/functions/bar/package.json
/functions/bar/node_modules
/package.json
/node_modules/

Zip It and Ship It will only include dependencies in each zip file that's been required from the relevant handler file.

File Serving

As of v0.3.0 the serveFunctions capability has been extracted out to Netlify Dev.

API

promise(zipped) = zipFunctions(source, destination, [opts])

Discover and zip all functions found in the source path into the destination. Returns a promise containing a zipped array of function objects.

The array of zipped function objects has the following shape:

[
  {
    path,  // Absolute filepath to zipped function
    runtime // 'go' or 'js'
  }
  //...
]

opts include:

{
  parallelLimit: 5, // Limit the number of concurrent zipping operations at a time
  skipGo: false // Don't zip go functions, just move them to the destination path
}

CLI

A minimal CLI version of zip-it-and-ship-it is provided for use inside the build-image, although this is automatically invoked on users behalf during builds and you typically do not need to run this yourself.

$ zip-it-and-ship-it --help
@netlify/zip-it-and-ship-it: Zip lambda functions and their dependencies for deployment

Usage: zip-it-and-ship-it [source] [destination] {options}
    --zip-go, -g          zip go binaries (default: false)
    --help, -h            show help
    --version, -v         print the version of the program

See Also

Check our official docs here.

You can’t perform that action at this time.