envelopes

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 12 Imported by: 0

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIGateway

func APIGateway[T any](payload parser.Schema[T]) parser.Schema[T]

APIGateway validates a REST event with the application's body schema.

func APIGatewayV2

func APIGatewayV2[T any](payload parser.Schema[T]) parser.Schema[T]

APIGatewayV2 validates an HTTP API v2 event with the application's body schema.

func CloudWatch

func CloudWatch[T any](payload parser.Schema[T]) parser.Schema[[]T]

CloudWatch decompresses the log envelope and validates each message string.

func DynamoDBStream

func DynamoDBStream[T any](payload parser.Schema[T]) parser.Schema[[]Images[T]]

DynamoDBStream preserves one old/new image pair per input record.

func EventBridge

func EventBridge[T any](payload parser.Schema[T]) parser.Schema[T]

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

func Kafka[T any](payload parser.Schema[T]) parser.Schema[[]T]

Kafka flattens topic-partition records after Base64-to-text decoding. RawMessage input preserves JSON topic order; Go maps use sorted topic keys.

func Kinesis

func Kinesis[T any](payload parser.Schema[T]) parser.Schema[[]T]

Kinesis validates the decoded JSON/text data provided by the Kinesis schema.

func KinesisFirehose

func KinesisFirehose[T any](payload parser.Schema[T]) parser.Schema[[]T]

KinesisFirehose passes decoded text to the payload schema; JSON parsing is explicit.

func LambdaFunctionURL

func LambdaFunctionURL[T any](payload parser.Schema[T]) parser.Schema[T]

LambdaFunctionURL uses the HTTP API v2 shape without implicit Base64 decoding.

func SNS

func SNS[T any](payload parser.Schema[T]) parser.Schema[[]T]

SNS passes the notification's Message string to the payload schema unchanged.

func SNSSQS

func SNSSQS[T any](payload parser.Schema[T]) parser.Schema[[]T]

SNSSQS decodes the notification JSON, then validates its Message string.

func SQS

func SQS[T any](payload parser.Schema[T]) parser.Schema[[]T]

SQS validates record metadata and passes each body string to the payload schema.

func VpcLattice

func VpcLattice[T any](payload parser.Schema[T]) parser.Schema[T]

VpcLattice validates the v1 event's snake_case metadata and body.

func VpcLatticeV2

func VpcLatticeV2[T any](payload parser.Schema[T]) parser.Schema[T]

VpcLatticeV2 validates the v2 event's camelCase metadata and body.

Types

type Images

type Images[T any] struct {
	NewImage *T `json:"NewImage,omitempty"`
	OldImage *T `json:"OldImage,omitempty"`
}

Images retains missing images separately from present images with zero values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL