lambda-build
will bundle your code (including node_modules) using esbuild, and create a zip filenpm i --save-dev lambda-build
npm i --g lambda-build
npx lambda-build --help
index.js|ts
, you can generate a local archive.zip
by running:npx lambda-build
archive.zip
filelambda-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
using -m
, generate a meta.json
file which you can then use to analyze your bundle:
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
build()
import { build } from 'lambda-build';
const res = await build({
entry: 'src/index.js',
external: ['lodash', 'dayjs'],
metafile: true,
});
res
object:
res.archive
- Buffer - contents of the zip archiveres.archiveSize
- string - the size of the archiveres.meta
- string - contents of the meta filebuildAndUpload()
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',
});
res
object:
res.archive
- Buffer - contents of the zip archiveres.archiveSize
- string - the size of the archiveres.meta
- string - contents of the meta fileupdatedArns
- string[] - an array with the ARNs of the lambda functions that were successfully deployed