Getting started¶
Prerequisites¶
- Node.js 22.20 or later, or 24.8 or later. The CLI uses Node's built-in glob support, which is stable from those versions. This is only for running the CLI; your function can use any Node.js Lambda runtime.
- An existing Lambda function using a Node.js runtime, ideally a dedicated development copy.
- AWS credentials that the AWS SDK can find: environment variables,
~/.aws/credentials, SSO, or an instance/container role. You can also name a profile per target. The credentials need the permissions in IAM permissions.
Install¶
Add it to the project that contains your handler:
Or run it without installing, using npx aws-lambda-dev or bunx aws-lambda-dev. The examples below use npx.
1. Create a config¶
This writes a starter lambda-dev.yml in the current directory. It won't overwrite an existing file. Its first line links the config schema, so most editors will autocomplete and check it as you type.
Edit it so the dev target points at your function and handler:
# yaml-language-server: $schema=https://harryvince.github.io/lambda-dev/schema.json
version: 1
defaultTarget: dev
targets:
dev:
functionName: my-existing-lambda-dev # (1)!
region: eu-west-2
build:
entry: src/handler.ts # (2)!
target: node20
external:
- "@aws-sdk/*" # (3)!
watch:
include:
- src/**/*.ts
invoke:
afterDeploy: true
payloadFile: events/dev.json # (4)!
- The name (or ARN) of a function that already exists.
- Your handler file, relative to
lambda-dev.yml. It's bundled toindex.js, so set the function's handler toindex.handler(orindex.<your export>). - The AWS SDK v3 ships with the Node.js Lambda runtimes, so it's usually left out of the bundle.
- A JSON event to send after each deploy. Remove
invokeif you don't want automatic invocations.
Handler setting
The zip contains index.js at its root, so the function's Handler setting in Lambda must be index.<export name>, e.g. index.handler. Set this once in the console or your infrastructure code.
2. Validate¶
This checks the YAML and the target selection without building or calling AWS.
3. Deploy once¶
Builds, uploads, and invokes the default target. Pass a target name to pick another one: npx aws-lambda-dev deploy staging.
4. Watch¶
Every save that matches watch.include runs a full build-upload-invoke cycle. Stop it with Ctrl+C.
A failed cycle (for example a type error that breaks the build) is logged and watch keeps running; fix the file and save again.
Tip
Add .lambda-dev/ to your .gitignore. It holds the build output for each target, the build cache, and the rollback snapshots, which include your function's environment variables.