AWS Lambda API Gateway Event TypeScript Types
TypeScript interfaces for the AWS Lambda API Gateway proxy event. Use these types when building Lambda functions behind API Gateway without installing @types/aws-lambda.
AWS Lambda — Sample JSON
{
"resource": "/api/users/{id}",
"path": "/api/users/123",
"httpMethod": "GET",
"headers": {
"Accept": "application/json",
"Authorization": "Bearer eyJhbGciOiJIUzI1NiJ9",
"Host": "api.example.com",
"User-Agent": "Mozilla/5.0"
},
"queryStringParameters": {
"include": "profile",
"format": "json"
},
"pathParameters": {
"id": "123"
},
"requestContext": {
"resourcePath": "/api/users/{id}",
"httpMethod": "GET",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
"stage": "prod",
"identity": {
"sourceIp": "12.34.56.78",
"userAgent": "Mozilla/5.0"
}
},
"body": null,
"isBase64Encoded": false
}Generated TypeScript
export interface Headers {
Accept: string;
Authorization: string;
Host: string;
"User-Agent": string;
}
export interface QueryStringParameters {
include: string;
format: string;
}
export interface PathParameters {
id: string;
}
export interface Identity {
sourceIp: string;
userAgent: string;
}
export interface RequestContext {
resourcePath: string;
httpMethod: string;
requestId: string;
stage: string;
identity: Identity;
}
export interface LambdaApiGatewayEvent {
resource: string;
path: string;
httpMethod: string;
headers: Headers;
queryStringParameters: QueryStringParameters;
pathParameters: PathParameters;
requestContext: RequestContext;
body: null | null;
isBase64Encoded: boolean;
}How to use
Copy the TypeScript above into a types.ts file in your project. Import the root interface and use it to type your API responses: const data: LambdaApiGatewayEvent = await res.json()
Working with a different JSON payload? Paste any JSON and generate TypeScript interfaces instantly.
Convert your own JSON →FAQ
How do I parse the request body in an AWS Lambda function?
The body field is a string (not parsed JSON). Parse it yourself: const data = event.body ? JSON.parse(event.body) : null. If isBase64Encoded is true, decode it first: const body = Buffer.from(event.body, 'base64').toString('utf-8').
What is the difference between queryStringParameters and multiValueQueryStringParameters?
queryStringParameters gives you one value per key (the last value wins if a key appears multiple times). multiValueQueryStringParameters gives you string[] per key for all values. Use multiValueQueryStringParameters when you need ?tag=a&tag=b to produce ['a', 'b'].
Do I need @types/aws-lambda for type safety in Lambda functions?
@types/aws-lambda is comprehensive and covers all event types (S3, SQS, DynamoDB streams, etc.). For functions that only handle API Gateway events, these generated types are sufficient and add zero dependencies. Install @types/aws-lambda if you need multiple event types.