@awsless/lambda
v0.0.27
Published
[![npm version](https://img.shields.io/npm/dw/@awsless/lambda)](https://www.npmjs.org/package/@awsless/lambda) [![npm version](https://img.shields.io/npm/v/@awsless/lambda.svg?style=flat-square)](https://www.npmjs.org/package/@awsless/lambda) [![license](
Downloads
246
Readme
TODO
- Rename ViewableError to ExpectedError
- Think of ways to type errors
Basic usage
import { lambda } from "@awsless/lambda";
// simple echo function
export default lambda({
handle(event) {
return event
}
})
import { lambda } from "@awsless/lambda";
import { object, string } from "@awsless/validate";
import { bugsnag } from "@awsless/bugsnag";
export default lambda({
// Validate the input
schema: object({
message: string()
}),
// Log errors to bugsnag
logger: bugsnag(),
handle({ message }) {
return message
}
})
Invoking a lambda
import { lambda, invoke } from "@awsless/lambda";
import { string } from "@awsless/validate";
export const echo = lambda({
schema: string(),
handle(value) {
return value
}
})
export default lambda({
handle() {
// Providing the type definition of the lambda you want to invoke will give you type hinting for the payload and return value.
return invoke<typeof echo>({
name: 'echo',
payload: 'Hi'
})
}
})
Mock invoking lambda's
import { mockLambda } from "@awsless/lambda";
const lambdas = mockLambda({
echo: a => a,
})
it('your test', async () => {
const result = await invoke({
name: 'echo',
payload: 'Hi'
})
expect(result).toBe('Hi')
expect(lambdas.echo).toBeCalled()
})