- Point it to a js/ts file containing your lambda handler(s)
lambda-buildwill 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
npm i --save-dev lambda-build- or globally:
npm i --g lambda-build- see options:
npx lambda-build --help- if your handler is called
index.js|ts, you can generate a localarchive.zipby 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.zipfile
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 ameta.jsonfile which you can then use to analyze your bundle:
npx lambda-build archive -e src/index.ts -mnpx 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
-rflag (otherwise it defaults tous-east-1):
npx lambda-build upload my-lambda1 my-lambda2 -e src/index.ts -r us-east-2import { build } from 'lambda-build';
const res = await build({
entry: 'src/index.js',
external: ['lodash', 'dayjs'],
metafile: true,
});- returns a
resobject:res.archive- Buffer - contents of the zip archiveres.archiveSize- string - the size of the archiveres.meta- string - contents of the meta file
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
resobject: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
- How to deploy a lambda function using versioning and aliases + API Gateway
- How to install npm modules in AWS Lambda?
- How to deploy a lambda function using github actions?
- How to use layers with Lambda functions?
- How to connect AWS Lambda to a MySQL database to update it? (using RDS proxy)
- How to use environment variables with a Lambda function? (and how to encrypt them with KMS)
- How to use ImageMagick with a Lambda function on AWS?
- How to pass a url query string or a route parameter to AWS Lambda from API Gateway?
- How to build a chat using Lambda + WebSocket + API Gateway? (nodejs)
- What is an AWS lambda function?
- How to restrict access to a static S3 site using HTTP Basic Auth?
- AWS Lambda intro - versions, aliases, concurrency, triggers, logs and monitoring
