1.4.0 • Published 1 year ago

ss-lambda v1.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

ss-lambda

All aboard the S.S. Lambda!

A super-simple lambda wrapper to make Lambda easy to work with in API gateways (or function URLs). Adds simple setup and types for a JSON request body, response body, and header overrides

installation

npm i ss-lambda

WIP

Usage

import ssLambda from "ss-lambda"

interface ExampleReqBody {
    id: string
    myType: number
}

interface ExampleQueryStringParams {
    id: string
}

export const post = ssLambda<ExampleReqBody, ExampleQueryStringParams>(
    async event => {
        const subscription = await getSubscriptionById(event.queryStringParameters.id)
        return { subscription }
    },
    {
        validators: [headersChecker],
    }
)

Validators

import { ApiError, WrapperValidator } from "ss-lambda"

const headersChecker: WrapperValidator = event => {
    if (!event.queryStringParameters.id) {
        // ApiError will always be 500 unless you specify one
        throw new ApiError("invalid request", 400)
    }
}

then add the function to the opts in ssLambda, ex:

export const post = ssLambda<ExampleReqBody, ExampleQueryStringParams>(
    async event => {
        const subscription = await getSubscriptionById(event.queryStringParameters.id)
        return { subscription }
    },
    {
        // highlight-next-line
        validators: [headersChecker],
    }
)
1.4.0

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago