Documentation
¶
Overview ¶
Package envelopes validates Lambda event envelopes and extracts typed payloads.
Construct an envelope schema around an application payload schema, then pass it to Parser's Parse or WrapHandler. SQS validates records and parses body strings; EventBridge validates metadata and selects detail. Other constructors support HTTP, stream, Kafka and service-specific envelopes.
Validation order ¶
Envelope schemas validate service metadata before delivering payloads to business code. Failures retain payload paths in Parser issues. Extraction and decoding differ by event family; the guide explains when to use a JSON-string schema or a schema for an already decoded value.
For usage and compatibility details, see the user guide.
Index ¶
- func APIGateway[T any](payload parser.Schema[T]) parser.Schema[T]
- func APIGatewayV2[T any](payload parser.Schema[T]) parser.Schema[T]
- func CloudWatch[T any](payload parser.Schema[T]) parser.Schema[[]T]
- func DynamoDBStream[T any](payload parser.Schema[T]) parser.Schema[[]Images[T]]
- func EventBridge[T any](payload parser.Schema[T]) parser.Schema[T]
- func Kafka[T any](payload parser.Schema[T]) parser.Schema[[]T]
- func Kinesis[T any](payload parser.Schema[T]) parser.Schema[[]T]
- func KinesisFirehose[T any](payload parser.Schema[T]) parser.Schema[[]T]
- func LambdaFunctionURL[T any](payload parser.Schema[T]) parser.Schema[T]
- func SNS[T any](payload parser.Schema[T]) parser.Schema[[]T]
- func SNSSQS[T any](payload parser.Schema[T]) parser.Schema[[]T]
- func SQS[T any](payload parser.Schema[T]) parser.Schema[[]T]
- func VpcLattice[T any](payload parser.Schema[T]) parser.Schema[T]
- func VpcLatticeV2[T any](payload parser.Schema[T]) parser.Schema[T]
- type Images
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func APIGateway ¶
APIGateway validates a REST event with the application's body schema.
func APIGatewayV2 ¶
APIGatewayV2 validates an HTTP API v2 event with the application's body schema.
func CloudWatch ¶
CloudWatch decompresses the log envelope and validates each message string.
func DynamoDBStream ¶
DynamoDBStream preserves one old/new image pair per input record.
func EventBridge ¶
EventBridge validates metadata together with the selected detail schema.
Example ¶
package main
import (
"context"
"fmt"
"github.com/rambow-cloud/powertools-lambda-go/parser"
"github.com/rambow-cloud/powertools-lambda-go/parser/envelopes"
)
func main() {
schema := envelopes.EventBridge(parser.Object(
parser.Field{Name: "orderId", Schema: parser.String()},
))
event := map[string]any{
"version": "0", "id": "example-event", "detail-type": "OrderCreated",
"source": "example.orders", "account": "000000000000",
"time": "2026-01-01T00:00:00Z", "region": "ap-east-1", "resources": []any{},
"detail": map[string]any{"orderId": "order-123"},
}
value, err := parser.Parse(context.Background(), event, schema)
if err != nil {
panic(err)
}
fmt.Println(value.(map[string]any)["orderId"])
}
Output: order-123
func Kafka ¶
Kafka flattens topic-partition records after Base64-to-text decoding. RawMessage input preserves JSON topic order; Go maps use sorted topic keys.
func KinesisFirehose ¶
KinesisFirehose passes decoded text to the payload schema; JSON parsing is explicit.
func LambdaFunctionURL ¶
LambdaFunctionURL uses the HTTP API v2 shape without implicit Base64 decoding.
func VpcLattice ¶
VpcLattice validates the v1 event's snake_case metadata and body.