The @types/aws-lambda
npm module has TypeScript declarations for various ways a Lambda function can be triggered. For example, if the Lambda function is triggered via API Gateway, you can write:
import { APIGatewayProxyHandler } from "aws-lambda";
export const handler: APIGatewayProxyHandler = async (
event,
context,
callback
) => {
...
}
This ensures event
, context
, and callback
have the appropriate types.
What's the equivalent code if the handler is being triggered via Lambda Function URLs?
tldr; The type of Lambda function URL event is the same as the API Gateway event.
Quoting from the AWS Lambda developer guide
When a client calls your function URL, Lambda maps the request to an event object before passing it to your function. Your function's response is then mapped to an HTTP response that Lambda sends back to the client through the function URL.
The request and response event formats follow the same schema as the Amazon API Gateway payload format version 2.0.