All Projects → netlify → Zip It And Ship It

netlify / Zip It And Ship It

Licence: mit
Intelligently prepare Node.js Lambda functions for deployment

Programming Languages

javascript
184084 projects - #8 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Zip It And Ship It

Webiny Js
Enterprise open-source serverless CMS. Includes a headless CMS, page builder, form builder and file manager. Easy to customize and expand. Deploys to AWS.
Stars: ✭ 4,869 (+4581.73%)
Mutual labels:  aws, serverless, lambda, lambda-functions
Aws Lambda List
A list of hopefully useful AWS lambdas and lambda-related resources.
Stars: ✭ 130 (+25%)
Mutual labels:  aws, serverless, lambda, lambda-functions
Lambcycle
🐑🛵 A declarative lambda middleware with life cycle hooks 🐑🛵
Stars: ✭ 88 (-15.38%)
Mutual labels:  aws, serverless, lambda, lambda-functions
Serverlessui
A command-line utility for deploying serverless applications to AWS. Complete with custom domains, deploy previews, TypeScript support, and more.
Stars: ✭ 434 (+317.31%)
Mutual labels:  aws, serverless, lambda, cli
Lambdalogs
A CLI tool to trace AWS Lambda calls over multiple CloudWatch log groups.
Stars: ✭ 18 (-82.69%)
Mutual labels:  aws, serverless, lambda, cli
Terraform Nextjs Plugin
A plugin to generate terraform configuration for Nextjs 8 and 9
Stars: ✭ 41 (-60.58%)
Mutual labels:  aws, serverless, lambda, cli
Aws Serverless Airline Booking
Airline Booking is a sample web application that provides Flight Search, Flight Payment, Flight Booking and Loyalty points including end-to-end testing, GraphQL and CI/CD. This web application was the theme of Build on Serverless Season 2 on AWS Twitch running from April 24th until end of August in 2019.
Stars: ✭ 1,290 (+1140.38%)
Mutual labels:  aws, serverless, lambda, lambda-functions
Binaryalert
BinaryAlert: Serverless, Real-time & Retroactive Malware Detection.
Stars: ✭ 1,125 (+981.73%)
Mutual labels:  aws, serverless, lambda
Ask Around Me
The Ask Around Me example serverless web application. See the Compute Blog series and video series for more information. Contact @jbesw for info.
Stars: ✭ 67 (-35.58%)
Mutual labels:  aws, serverless, lambda
Aws Cli Cheatsheet
☁️ AWS CLI + JQ = Make life easier
Stars: ✭ 94 (-9.62%)
Mutual labels:  aws, lambda, cli
Lambda Refarch Webapp
The Web Application reference architecture is a general-purpose, event-driven, web application back-end that uses AWS Lambda, Amazon API Gateway for its business logic. It also uses Amazon DynamoDB as its database and Amazon Cognito for user management. All static content is hosted using AWS Amplify Console.
Stars: ✭ 1,208 (+1061.54%)
Mutual labels:  aws, serverless, lambda
Aws Lambda Vpc Nat Examples
Example of setting up AWS lambda function with VPC and NAT
Stars: ✭ 92 (-11.54%)
Mutual labels:  aws, serverless, lambda
Serverless Api Example
Example of a Golang, Serverless API
Stars: ✭ 62 (-40.38%)
Mutual labels:  aws, serverless, lambda
Serverless Slackbot
A boilerplate Serverless Slackbot framework with a custom scripts folder (like Hubot)
Stars: ✭ 72 (-30.77%)
Mutual labels:  aws, serverless, lambda
Up
Up focuses on deploying "vanilla" HTTP servers so there's nothing new to learn, just develop with your favorite existing frameworks such as Express, Koa, Django, Golang net/http or others.
Stars: ✭ 8,439 (+8014.42%)
Mutual labels:  aws, serverless, lambda
Serverless Node Simple Messaging
Simple email AWS lambda function
Stars: ✭ 75 (-27.88%)
Mutual labels:  aws, serverless, lambda
Apex
Old apex/apex
Stars: ✭ 20 (-80.77%)
Mutual labels:  aws, serverless, lambda
Serverless Node Simple Image Resize
Simple image resize AWS lambda function
Stars: ✭ 74 (-28.85%)
Mutual labels:  aws, serverless, lambda
Awesome Aws
A curated list of awesome Amazon Web Services (AWS) libraries, open source repos, guides, blogs, and other resources. Featuring the Fiery Meter of AWSome.
Stars: ✭ 9,895 (+9414.42%)
Mutual labels:  aws, serverless, lambda
Historical
A serverless, event-driven AWS configuration collection service with configuration versioning.
Stars: ✭ 85 (-18.27%)
Mutual labels:  aws, serverless, lambda

zip-it-and-ship-it

npm version Coverage Status Build Downloads

Creates Zip archives from Node.js, Go, and Rust programs. Those archives are ready to be uploaded to AWS Lambda.

This library is used under the hood by several Netlify features, including production CI builds, Netlify CLI and the JavaScript client.

Check Netlify documentation for:

Installation

npm install @netlify/zip-it-and-ship-it

Usage (Node.js)

zipFunctions(srcFolder, destFolder, options?)

srcFolder: string
destFolder: string
options: object?
Return value: Promise<object[]>

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

const zipNetlifyFunctions = async function () {
  const archives = await zipFunctions('functions', 'functions-dist')
  return archives
}

Creates Zip archives from Node.js, Go, and Rust programs. Those archives are ready to be uploaded to AWS Lambda.

srcFolder is the source files directory. It must exist. In Netlify, this is the "Functions folder".

srcFolder can contain:

  • Sub-directories with a main file called either index.js or {dir}.js where {dir} is the sub-directory name.
  • .js files (Node.js)
  • .zip archives with Node.js already ready to upload to AWS Lambda.
  • Go programs already compiled. Those are copied as is.
  • Rust programs already compiled. Those are zipped.

When using Node.js files, only the dependencies required by the main file are bundled, in order to keep the archive as small as possible, which improves the Function runtime performance:

  • All files/directories within the same directory (except node_modules) are included
  • All the require()'d files are included
  • All the require()'d node_modules are included, recursively
  • The following modules are never included:
    • @types/* TypeScript definitions
    • aws-sdk
  • Temporary files like *~, *.swp, etc. are not included

This is done by parsing the JavaScript source in each Function file, and reading the package.json of each Node module.

destFolder is the directory where each .zip archive should be output. It is created if it does not exist. In Netlify CI, this is an unspecified temporary directory inside the CI machine. In Netlify CLI, this is a .netlify/functions directory in your build directory.

Options

config

Type: object
Default value: {}

An object matching glob-like expressions to objects containing configuration properties. Whenever a function name matches one of the expressions, it inherits the configuration properties.

The following properties are accepted:

  • externalNodeModules

    Type: array<string>\

    List of Node modules to include separately inside a node_modules directory.

  • ignoredNodeModules

    Type: array<string>\

    List of Node modules to keep out of the bundle.

  • nodeBundler

    Type: string
    Default value: zisi

    The bundler to use when processing JavaScript functions. Possible values: zisi, esbuild, esbuild_zisi.

    When the value is esbuild_zisi, esbuild will be used with a fallback to zisi in case of an error.

parallelLimit

Type: number
Default value: 5

Maximum number of Functions to bundle at the same time.

Return value

This returns a Promise resolving to an array of objects describing each archive. Each object has the following properties.

path

Type: string

Absolute file path to the archive file.

runtime

Type: string

Either "js", "go", or "rs".

zipFunction(srcPath, destFolder, options?)

srcPath: string
destFolder: string
options: object?
Return value: object | undefined

const { zipFunction } = require('@netlify/zip-it-and-ship-it')

const zipNetlifyFunctions = async function () {
  const archive = await zipFunctions('functions/function.js', 'functions-dist')
  return archive
}

This is like zipFunctions() except it bundles a single Function.

The return value is undefined if the Function is invalid.

listFunctions(srcFolder)

srcFolder: string
Return value: Promise<object[]>

Returns the list of Functions to bundle.

const { listFunctions } = require('@netlify/zip-it-and-ship-it')

const listNetlifyFunctions = async function () {
  const functions = await listFunctions('functions/function.js')
  return functions
}

Return value

Each object has the following properties.

name

Type: string

Function's name. This is the one used in the Function URL. For example, if a Function is a myFunc.js regular file, the name is myFunc and the URL is https://{hostname}/.netlify/functions/myFunc.

mainFile

Type: string

Absolute path to the Function's main file. If the Function is a Node.js directory, this is its index.js or {dir}.js file.

runtime

Type: string

Either "js", "go", or "rs".

extension

Type: string

Source file extension. For Node.js, this is either .js or .zip. For Go, this can be anything.

listFunctionsFiles(srcFolder)

srcFolder: string
Return value: Promise<object[]>

Like listFunctions(), except it returns not only the Functions main files, but also all their required files. This is much slower.

const { listFunctionsFiles } = require('@netlify/zip-it-and-ship-it')

const listNetlifyFunctionsFiles = async function () {
  const functions = await listFunctionsFiles('functions/function.js')
  return functions
}

Return value

The return value is the same as listFunctions() but with the following additional properties.

srcFile

Type: string

Absolute file to the source file.

Usage (CLI)

$ zip-it-and-ship-it srcFolder destFolder

The CLI performs the same logic as zipFunctions(). The archives are printed on stdout as a JSON array.

Troubleshooting

Build step

zip-it-and-ship-it does not build, transpile nor install the dependencies of the Functions. This needs to be done before calling zip-it-and-ship-it.

Missing dependencies

If a Node module require() another Node module but does not list it in its package.json (dependencies, peerDependencies or optionalDependencies), it is not bundled, which might make the Function fail.

More information in this issue.

Conditional require

Files required with a require() statement inside an if or try/catch block are always bundled.

More information in this issue.

Dynamic require

Files required with a require() statement whose argument is not a string literal, e.g. require(variable), are never bundled.

More information in this issue.

Node.js native modules

If your Function or one of its dependencies uses Node.js native modules, the Node.js version used in AWS Lambda might need to be the same as the one used when installing those native modules.

In Netlify, this is done by ensuring that the following Node.js versions are the same:

Note that this problem might not apply for Node.js native modules using the N-API.

More information in this issue.

File Serving

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].