What is @netlify/zip-it-and-ship-it?
@netlify/zip-it-and-ship-it is a Node.js library designed to bundle and package functions for deployment on Netlify. It helps in zipping up serverless functions and their dependencies, making it easier to deploy them to Netlify's platform.
What are @netlify/zip-it-and-ship-it's main functionalities?
Bundling Functions
This feature allows you to bundle serverless functions from a source directory and output the bundled files to a target directory. The `zipFunctions` method takes two arguments: the source directory and the output directory.
const { zipFunctions } = require('@netlify/zip-it-and-ship-it');
zipFunctions('src/functions', 'out/functions')
.then(results => console.log('Functions bundled:', results))
.catch(error => console.error('Error bundling functions:', error));
Detecting Function Dependencies
This feature helps in detecting the dependencies of the functions in a given directory. The `listFunctions` method takes the source directory as an argument and returns a list of functions along with their dependencies.
const { listFunctions } = require('@netlify/zip-it-and-ship-it');
listFunctions('src/functions')
.then(results => console.log('Function dependencies:', results))
.catch(error => console.error('Error listing functions:', error));
Zipping Individual Functions
This feature allows you to zip an individual function file and output it as a zip file. The `zipFunction` method takes two arguments: the path to the function file and the output path for the zip file.
const { zipFunction } = require('@netlify/zip-it-and-ship-it');
zipFunction('src/functions/myFunction.js', 'out/functions/myFunction.zip')
.then(result => console.log('Function zipped:', result))
.catch(error => console.error('Error zipping function:', error));
Other packages similar to @netlify/zip-it-and-ship-it
serverless
The Serverless Framework is a comprehensive toolkit for deploying serverless applications. It supports multiple cloud providers and offers extensive functionality for managing serverless functions, including packaging and deployment. Compared to @netlify/zip-it-and-ship-it, Serverless Framework is more feature-rich and supports a wider range of cloud providers.
architect
Architect (or Arc) is a framework for building and deploying serverless applications. It focuses on simplicity and developer experience, offering tools for defining and deploying serverless functions. While Architect provides similar packaging and deployment capabilities, it is more opinionated and tightly integrated with AWS services compared to @netlify/zip-it-and-ship-it.
claudia
Claudia.js is a tool for deploying Node.js projects to AWS Lambda and API Gateway. It simplifies the process of packaging and deploying serverless functions. Claudia.js is more AWS-centric and offers less flexibility in terms of cloud provider support compared to @netlify/zip-it-and-ship-it.
zip-it-and-ship-it
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:
const zipped = [
{
path,
runtime
}
]
opts
include:
{
parallelLimit: 5,
skipGo: false
}
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.