tessl install tessl/pypi-aws-lambda-powertools@3.19.0Comprehensive developer toolkit implementing serverless best practices for AWS Lambda functions in Python
Agent Success
Agent success rate when using this tile
89%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.22x
Baseline
Agent success rate without this tile
73%
Build a Lambda function that transforms log records from Kinesis Data Firehose by filtering, enriching, and formatting them before delivery to S3.
Your Lambda function should:
Filter logs by severity: Only process records with log level "ERROR" or "WARN". Drop all other records.
Parse and validate: Parse each record as JSON. If parsing fails, mark the record as processing failed.
Enrich records: Add a processed_at timestamp field (ISO 8601 format) to each valid record.
Format output: Return transformed records as JSON strings, properly base64-encoded.
Handle status codes: Return appropriate result codes:
Each incoming record contains:
recordId: Unique identifier for the recorddata: Base64-encoded JSON string with fields:
level: Log level (DEBUG, INFO, WARN, ERROR)message: Log message texttimestamp: Original log timestampReturn a response with transformed records containing:
recordId: Original record IDresult: Status code (Ok, Dropped, or ProcessingFailed)data: Base64-encoded transformed JSON (for Ok status)@generates
def lambda_handler(event: dict, context: Any) -> dict:
"""
Transform Kinesis Firehose records.
Args:
event: Firehose transformation event
context: Lambda context
Returns:
Firehose transformation response with records
"""Provides event handling and data transformation utilities for AWS Lambda.