Giter Club home page Giter Club logo

lambda-build's Introduction

lambda action

How it works

  • Point it to a js/ts file containing your lambda handler(s)
  • lambda-build will bundle your code (including node_modules) using esbuild, and create a zip file
  • It can also upload the zip file to aws for you, all in a single command

Install

npm i --save-dev lambda-build
  • or globally:
npm i --g lambda-build
  • see options:
npx lambda-build --help

CLI Usage

  • if your handler is called index.js|ts, you can generate a local archive.zip by running:
npx lambda-build
  • use upload to create a bundle and upload it to aws
  • use archive to create a bundle and save it as a local archive.zip file

lambda-build archive

npx lambda-build archive bundles your code and creates a local archive.zip file that you can then upload to aws yourself.

  • using -e, set a custom entry file:
npx lambda-build archive -e src/index.ts
  • using -x, exclude some libraries from bundling (for example, if you already load them in a layer):
npx lambda-build archive -e src/index.ts -x lodash dayjs
npx lambda-build archive -e src/index.ts -m

lambda-build upload

npx lambda-build upload bundles your code and then uploads it directly to your AWS lambda functions (requires the aws cli to be locally configured).

  • specify the lambda functions that you would like to deploy to:
npx lambda-build upload my-lambda1 my-lambda2 -e src/index.ts
  • you can specify the region using the -r flag (otherwise it defaults to us-east-1):
npx lambda-build upload my-lambda1 my-lambda2 -e src/index.ts -r us-east-2

Library Usage

build()

import { build } from 'lambda-build';

const res = await build({
  entry: 'src/index.js',
  external: ['lodash', 'dayjs'],
  metafile: true,
});
  • returns a res object:
    • res.archive - Buffer - contents of the zip archive
    • res.archiveSize - string - the size of the archive
    • res.meta - string - contents of the meta file

buildAndUpload()

import { buildAndUpload } from 'lambda-build';

const res = await buildAndUpload({
  entry: 'src/index.js',
  external: ['lodash', 'dayjs'],
  metafile: true,
  lambdas: ['my-lambda1', 'my-lambda2'],
  region: 'us-east-2',
});
  • returns a res object:
    • res.archive - Buffer - contents of the zip archive
    • res.archiveSize - string - the size of the archive
    • res.meta - string - contents of the meta file
    • updatedArns - string[] - an array with the ARNs of the lambda functions that were successfully deployed

Screencast

lambda-build screencast

More Lambda Screencasts

Follow me for updates

lambda-build's People

Contributors

alexkrkn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.