or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

core-parsing.mdenvelopes.mderrors.mdhelpers.mdindex.mdmiddleware.mdparser-decorator.mdschemas.md
tile.json

schemas.mddocs/

Built-in Schemas

97+ pre-built Zod schemas for AWS Lambda event sources. All schemas provide TypeScript type inference and validation.

Import

import { EventBridgeSchema, SqsSchema, /* ... */ } from '@aws-lambda-powertools/parser/schemas';

Usage Pattern

// Direct usage
const sqsEvent = SqsSchema.parse(event);

// With parse function
const validatedEvent = parse(event, undefined, EventBridgeSchema);

// With envelope (extracts nested data)
const orders = parse(event, SqsEnvelope, orderSchema);

// Extend with custom validation
const TypedEventBridgeSchema = EventBridgeSchema.extend({
  detail: z.object({ orderId: z.string(), amount: z.number() })
});

Schema Reference

API Gateway

SchemaEvent TypeKey Fields
APIGatewayProxyEventSchemaREST API v1httpMethod, path, body, headers, queryStringParameters, pathParameters
APIGatewayProxyEventV2SchemaHTTP API v2routeKey, rawPath, body, headers, requestContext
APIGatewayProxyWebsocketEventSchemaWebSocketrequestContext.eventType (CONNECT/DISCONNECT/MESSAGE), body
APIGatewayRequestAuthorizerEventSchemaREQUEST authorizertype: 'REQUEST', methodArn, headers
APIGatewayTokenAuthorizerEventSchemaTOKEN authorizertype: 'TOKEN', authorizationToken, methodArn
APIGatewayRequestAuthorizerEventV2SchemaHTTP API authorizerversion: '2.0', routeArn, identitySource

AppSync

SchemaEvent TypeKey Fields
AppSyncResolverSchemaDirect resolverarguments, identity, source, info.fieldName
AppSyncBatchResolverSchemaBatch resolverArray of resolver events
AppSyncEventsPublishSchemaPublish eventevents[].payload, info.channel.path
AppSyncEventsSubscribeSchemaSubscribe eventinfo.operation: 'SUBSCRIBE'

CloudFormation

SchemaEvent TypeKey Fields
CloudFormationCustomResourceCreateSchemaCreateRequestType: 'Create', ResourceProperties
CloudFormationCustomResourceUpdateSchemaUpdateRequestType: 'Update', OldResourceProperties
CloudFormationCustomResourceDeleteSchemaDeleteRequestType: 'Delete', PhysicalResourceId

CloudWatch

SchemaEvent TypeKey Fields
CloudWatchLogsSchemaLog subscriptionawslogs.data (auto-decompressed)
CloudWatchLogsDecodeSchemaDecoded logslogGroup, logStream, logEvents[]

Cognito

SchemaTrigger TypeKey Fields
CreateAuthChallengeTriggerSchemaCreate Auth Challengerequest.challengeName, response.{publicChallengeParameters,privateChallengeParameters}
CustomEmailSenderTriggerSchemaCustom Emailrequest.code, request.userAttributes
CustomMessageTriggerSchemaCustom Messagerequest.codeParameter, response.{emailMessage,smsMessage}
DefineAuthChallengeTriggerSchemaDefine Auth Challengerequest.session[], response.{challengeName,issueTokens}
PreSignupTriggerSchemaPre Signuprequest.userAttributes, response.auto{ConfirmUser,VerifyEmail,VerifyPhone}
PostAuthenticationTriggerSchemaPost Authenticationrequest.newDeviceUsed
PreTokenGenerationTriggerSchemaV1Pre Token Gen v1request.groupConfiguration
PreTokenGenerationTriggerSchemaV2AndV3Pre Token Gen v2/v3request.scopes
VerifyAuthChallengeTriggerSchemaVerify Challengerequest.challengeAnswer, response.answerCorrect

DynamoDB

SchemaEvent TypeKey Fields
DynamoDBStreamSchemaStream eventRecords[].{eventName,dynamodb.{NewImage,OldImage}} (auto-unmarshalled)
DynamoDBStreamRecordSingle recordeventName: 'INSERT'/'MODIFY'/'REMOVE', dynamodb
DynamoDBStreamToKinesisRecordStream via KinesistableName, dynamodb (auto-unmarshalled)

EventBridge

SchemaEvent TypeKey Fields
EventBridgeSchemaEventsource, detail-type, detail, resources[]

Kafka

SchemaEvent TypeKey Fields
KafkaMskEventSchemaMSKeventSource: 'aws:kafka', records[topic][] (value auto-decoded)
KafkaSelfManagedEventSchemaSelf-managedeventSource: 'SelfManagedKafka', records[topic][]
KafkaRecordSchemaSingle recordtopic, partition, offset, value (auto-decoded), key (auto-decoded)

Kinesis

SchemaEvent TypeKey Fields
KinesisDataStreamSchemaData StreamRecords[].kinesis.data (auto-decoded from base64)
KinesisFirehoseSchemaFirehoserecords[].data (auto-decoded), deliveryStreamArn
KinesisFirehoseSqsSchemaFirehose + SQSrecords[].data (decoded as SQS record)
KinesisDynamoDBStreamSchemaDynamoDB via KinesisRecords[].kinesis.data (decoded as DynamoDB record)

S3

SchemaEvent TypeKey Fields
S3SchemaS3 notificationRecords[].s3.{bucket.name,object.key}
S3EventNotificationEventBridgeSchemaS3 via EventBridgedetail.{bucket.name,object.key}
S3ObjectLambdaEventSchemaObject LambdagetObjectContext, userRequest
S3SqsEventNotificationSchemaS3 via SQSRecords[].body (parsed as S3 event)

SES

SchemaEvent TypeKey Fields
SesSchemaEmail receiptRecords[].ses.{mail,receipt.{spamVerdict,virusVerdict}}

SNS

SchemaEvent TypeKey Fields
SnsSchemaSNS notificationRecords[].Sns.{Message,Subject,TopicArn}
SnsSqsNotificationSchemaSNS via SQSMessage (from SQS body)

SQS

SchemaEvent TypeKey Fields
SqsSchemaSQS messageRecords[].{body,messageId,receiptHandle,attributes}

Other Services

SchemaEvent TypeKey Fields
AlbSchemaApplication Load BalancerhttpMethod, path, body, headers
LambdaFunctionUrlSchemaFunction URLversion, routeKey, body, headers
TransferFamilySchemaTransfer Family authusername, password, protocol, serverId
VpcLatticeSchemaVPC Lattice v1method, raw_path, body
VpcLatticeV2SchemaVPC Lattice v2method, path, body, requestContext

Composition Examples

Extend Schema with Typed Detail

const OrderEventSchema = EventBridgeSchema.extend({
  detail: z.object({
    orderId: z.string(),
    amount: z.number().positive(),
    status: z.enum(['pending', 'completed']),
  }),
});

const orderEvent = OrderEventSchema.parse(event);
// orderEvent.detail is now strongly typed

Parse JSON Body with Helper

const TypedSqsSchema = z.object({
  Records: z.array(
    z.object({
      body: JSONStringified(z.object({
        orderId: z.string(),
        items: z.array(z.string()),
      })),
      messageId: z.string(),
    })
  ),
});

const sqsEvent = TypedSqsSchema.parse(event);
// body is automatically parsed from JSON

Combine Helpers for Complex Data

// Base64-encoded, gzipped JSON in Kinesis
const recordSchema = KinesisDataStreamRecord.extend({
  kinesis: z.object({
    data: Base64Encoded(JSONStringified(z.object({
      userId: z.string(),
      action: z.string(),
    }))),
  }).passthrough(),
});

Type Exports

All AWS event types are exported:

import type {
  EventBridgeEvent,
  SqsEvent,
  SqsRecord,
  DynamoDBStreamEvent,
  S3Event,
  // ... and more
} from '@aws-lambda-powertools/parser/types';