@polarity-dev/lambda-local-runner
v0.0.8
Published
This project provides a local environment to run and test AWS Lambda functions using Node.js.
Readme
Lambda Local Runner
This project provides a local environment to run and test AWS Lambda functions using Node.js.
Usage
npm install -g @polarity-dev/lambda-local-runner
echo '{ "my-function": "/path/to/function.js" }' > lambda.json
lambda-local --config lambda.jsonBuild from source
TL;DR
npm install
cp lambda-sample.json lambda.json
npm run dev aRequirements
- Node.js
Setup Instructions
Install Dependencies. Run the following command to install necessary dependencies:
npm installCreate Lambda Mapping Settings. Copy the sample Lambda configuration file:
cp lambda-sample.json lambda.jsonThen, fill in the details for the Lambda function you intend to manage.
Running the Server
To start the local Lambda server, execute:
npm run devOnce the server is running, you can invoke your local Lambda functions by using localhost:6789 as the endpoint. Below is an example of how to call a Lambda function using the AWS SDK for JavaScript:
import { LambdaClient, InvokeCommand } from "@aws-sdk/client-lambda"
const lambdaClient = new LambdaClient({
region: "eu-west-1",
endpoint: "http://localhost:6789",
})
lambdaClient.send(
new InvokeCommand({
FunctionName: "my-function",
Payload: JSON.stringify({ hello: "world" })
})
)
.then(console.log)
.catch(console.log)
Testing
Lambda Functions
A minimal example of a JavaScript Lambda function can be found in tests/my-function/index.js
Invoking Lambda Functions
A minimal example of a JavaScript Lambda invoking can be found in tests/invoke-test.ts. To test run the following command:
npm run test:invoke