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 processes e-commerce order events and emits custom CloudWatch metrics with dimensional data and contextual metadata for analytics and monitoring.
You are building an observability system for an e-commerce platform. The system needs to track order processing metrics with rich dimensional data (for aggregation and filtering) and metadata (for detailed investigation).
Your Lambda function will:
The Lambda function receives events with this structure:
{
"order_id": "ORD-12345",
"region": "us-west",
"product_category": "Electronics",
"payment_method": "credit_card",
"order_value": 299.99,
"quantity": 2,
"customer_segment": "premium",
"promotion_code": "SUMMER2024",
"warehouse_location": "warehouse-seattle-01",
"status": "completed"
}Emit the following metrics with appropriate units:
Add the following dimensions to ALL metrics for filtering and aggregation:
These dimensions should allow CloudWatch to aggregate metrics by any combination of these attributes.
Add the following as metadata (NOT dimensions) for detailed investigation:
Metadata should be searchable in CloudWatch Logs Insights but should not count toward dimension limits.
EcommerceMetricsOrderProcessingInput Event:
{
"order_id": "ORD-001",
"region": "us-east",
"product_category": "Books",
"payment_method": "paypal",
"order_value": 45.50,
"quantity": 3,
"customer_segment": "standard",
"promotion_code": "BOOKWORM",
"warehouse_location": "warehouse-nyc-02",
"status": "completed"
}Expected Behavior:
Input Event:
{
"order_id": "ORD-002",
"region": "eu-west",
"product_category": "Electronics",
"payment_method": "credit_card",
"order_value": 1299.99,
"quantity": 1,
"customer_segment": "premium",
"promotion_code": "VIP10",
"warehouse_location": "warehouse-london-01",
"status": "completed"
}Expected Behavior:
Create the following files:
src/
├── handler.py # Lambda handler function
└── handler_test.py # Test file with test casesProvides observability utilities for AWS Lambda functions including structured logging, metrics, and tracing.