AWS Lambda compatibility wrapper for Netlify Functions. Lets you author Netlify Functions using the AWS Lambda handler signature.
npm install @netlify/aws-lambda-compatWrap your Lambda-style handler with withLambda and export the result as your Netlify Function:
import { withLambda } from '@netlify/aws-lambda-compat'
import type { HandlerEvent, HandlerContext, HandlerResponse } from '@netlify/aws-lambda-compat'
export default withLambda(async (event: HandlerEvent, context: HandlerContext): Promise<HandlerResponse> => {
const name = event.queryStringParameters?.name ?? 'World'
return {
statusCode: 200,
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ message: `Hello, ${name}!` }),
}
})withLambda converts between the two function signatures:
- Incoming
Requestis converted to a LambdaHandlerEvent(URL, headers, query string, body with automatic base64 encoding for binary payloads) - The Netlify
Contextis mapped to aHandlerContextwith sensible defaults for AWS-specific fields - The
HandlerResponsereturned by your handler is converted back to a web-standardResponse
The package exports the following AWS Lambda-compatible types:
HandlerHandlerCallbackHandlerContextHandlerEventHandlerResponse
Additionally, the package exports:
LambdaHandler— the type of the handler function passed towithLambda
Please see CONTRIBUTING.md for instructions on how to set up and work on this repository. Thanks for contributing!