67
loading...
This website collects cookies to deliver better user experience
event
: Which contains information about the specific invocation of the Lambda.context
: Which contains information about the Lambda function itself.result
: In which we define the response for the Lambda invocation.yarn add -D @types/aws-lambda
npm i @types/aws-lambda --save-dev
export type APIGatewayProxyHandler = Handler<APIGatewayProxyEvent, APIGatewayProxyResult>;
export type APIGatewayProxyHandlerV2<T = never> = Handler<APIGatewayProxyEventV2, APIGatewayProxyResultV2<T>>;
export interface APIGatewayEventRequestContextV2 { ... }
2.0
the result of the invocation can an object or a string as well, so the following are also valid declarations for the handler (see Lambda function response format):export type APIGatewayProxyHandlerV2<T = never> = Handler<APIGatewayProxyEventV2, any>;
export type APIGatewayProxyHandlerV2<T = never> = Handler<APIGatewayProxyEventV2, string>;
any
with your own custom type.import {
Handler,
APIGatewayProxyEventV2,
APIGatewayProxyResultV2,
} from 'aws-lambda';
type ProxyHandler = Handler<APIGatewayProxyEventV2, APIGatewayProxyResultV2>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const handler: ProxyHandler = async (event, context) => {
return {
statusCode: 201,
body: JSON.stringify({
message: 'Unknown endpoint',
}),
};
};
import { Handler, APIGatewayProxyEventV2 } from 'aws-lambda';
type ProxyHandler = Handler<APIGatewayProxyEventV2, any>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const handler: ProxyHandler = async (event, context) => {
const message = event.queryStringParameters?.message || 'no message';
return {
message: `${message}`,
};
};