# AWS API Gateway Event

> AWS API Gateway v1 proxy event with headers, params, body, and request context.

- Name: `aws-api-gateway-event`
- Categories: aws
- Detail page: https://open-types.dev/types/aws-api-gateway-event

## Install

```bash
# Types only
npx shadcn add @open-types/aws-api-gateway-event

# Types + Zod v4 validators
npx shadcn add @open-types/aws-api-gateway-event-zod

# Types + real-world examples
npx shadcn add @open-types/aws-api-gateway-event-examples
```

## Types

```typescript
export interface AWSAPIGatewayRequestIdentity {
  sourceIp: string;
  userAgent: string;
}

export interface AWSAPIGatewayRequestContext {
  accountId: string;
  apiId: string;
  httpMethod: string;
  identity: AWSAPIGatewayRequestIdentity;
  path: string;
  protocol: string;
  requestId: string;
  requestTimeEpoch: number;
  resourceId: string;
  resourcePath: string;
  stage: string;
}

export interface AWSAPIGatewayEvent {
  resource: string;
  path: string;
  httpMethod: string;
  headers: Record<string, string> | null;
  queryStringParameters: Record<string, string> | null;
  pathParameters: Record<string, string> | null;
  stageVariables: Record<string, string> | null;
  requestContext: AWSAPIGatewayRequestContext;
  body: string | null;
  isBase64Encoded: boolean;
}
```

## Zod validator

```typescript
import * as z from "zod";
import type {
  AWSAPIGatewayRequestIdentity,
  AWSAPIGatewayRequestContext,
  AWSAPIGatewayEvent,
} from "../types/aws-api-gateway-event";

export const awsApiGatewayRequestIdentitySchema = z.object({
  sourceIp: z.string(),
  userAgent: z.string(),
}) satisfies z.ZodType<AWSAPIGatewayRequestIdentity>;

export const awsApiGatewayRequestContextSchema = z.object({
  accountId: z.string(),
  apiId: z.string(),
  httpMethod: z.string(),
  identity: awsApiGatewayRequestIdentitySchema,
  path: z.string(),
  protocol: z.string(),
  requestId: z.string(),
  requestTimeEpoch: z.number(),
  resourceId: z.string(),
  resourcePath: z.string(),
  stage: z.string(),
}) satisfies z.ZodType<AWSAPIGatewayRequestContext>;

export const awsApiGatewayEventSchema = z.object({
  resource: z.string(),
  path: z.string(),
  httpMethod: z.string(),
  headers: z.record(z.string(), z.string()).nullable(),
  queryStringParameters: z.record(z.string(), z.string()).nullable(),
  pathParameters: z.record(z.string(), z.string()).nullable(),
  stageVariables: z.record(z.string(), z.string()).nullable(),
  requestContext: awsApiGatewayRequestContextSchema,
  body: z.string().nullable(),
  isBase64Encoded: z.boolean(),
}) satisfies z.ZodType<AWSAPIGatewayEvent>;

export type {
  AWSAPIGatewayRequestIdentity,
  AWSAPIGatewayRequestContext,
  AWSAPIGatewayEvent,
} from "../types/aws-api-gateway-event";
```

## Examples

```typescript
// Source: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format
// Captured: 2026-05
import type {
  AWSAPIGatewayRequestIdentity,
  AWSAPIGatewayRequestContext,
  AWSAPIGatewayEvent,
} from "../types/aws-api-gateway-event";

const identity = {
  sourceIp: "203.0.113.10",
  userAgent: "curl/8.7.1",
} as const satisfies AWSAPIGatewayRequestIdentity;

export const awsApiGatewayRequestIdentityExamples = {
  curl: identity,
  browser: {
    sourceIp: "198.51.100.7",
    userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15",
  } satisfies AWSAPIGatewayRequestIdentity,
} as const;

const requestContext = {
  accountId: "123456789012",
  apiId: "a1b2c3d4e5",
  httpMethod: "GET",
  identity,
  path: "/prod/orders/42",
  protocol: "HTTP/1.1",
  requestId: "c0ffee12-3456-7890-abcd-ef1234567890",
  requestTimeEpoch: 1713012345678,
  resourceId: "abc123",
  resourcePath: "/orders/{id}",
  stage: "prod",
} as const satisfies AWSAPIGatewayRequestContext;

export const awsApiGatewayRequestContextExamples = {
  get: requestContext,
  post: {
    ...requestContext,
    httpMethod: "POST",
    path: "/prod/orders",
    resourcePath: "/orders",
  } satisfies AWSAPIGatewayRequestContext,
} as const;

const getEvent = {
  resource: "/orders/{id}",
  path: "/prod/orders/42",
  httpMethod: "GET",
  headers: {
    Accept: "application/json",
    Host: "a1b2c3d4e5.execute-api.us-east-1.amazonaws.com",
  },
  queryStringParameters: { include: "items" },
  pathParameters: { id: "42" },
  stageVariables: { environment: "production" },
  requestContext,
  body: null,
  isBase64Encoded: false,
} as const satisfies AWSAPIGatewayEvent;

export const awsApiGatewayEventExamples = {
  get: getEvent,
  postWithBody: {
    ...getEvent,
    resource: "/orders",
    path: "/prod/orders",
    httpMethod: "POST",
    headers: { "Content-Type": "application/json" },
    queryStringParameters: null,
    pathParameters: null,
    body: '{"item":"sku_123","quantity":2}',
    requestContext: awsApiGatewayRequestContextExamples.post,
  } satisfies AWSAPIGatewayEvent,
  base64Body: {
    ...getEvent,
    httpMethod: "PUT",
    body: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=",
    isBase64Encoded: true,
  } satisfies AWSAPIGatewayEvent,
  allNullCollections: {
    ...getEvent,
    headers: null,
    queryStringParameters: null,
    pathParameters: null,
    stageVariables: null,
    body: null,
  } satisfies AWSAPIGatewayEvent,
} as const;
```
