or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/aws-lambda-powertools@3.19.x
tile.json

tessl/pypi-aws-lambda-powertools

tessl install tessl/pypi-aws-lambda-powertools@3.19.0

Comprehensive 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%

task.mdevals/scenario-2/

Order Processing Lambda Handler

Build a Lambda function that processes incoming order events from an SQS queue. The function should validate and process each order, handle failures gracefully, and only report back messages that could not be successfully processed.

Requirements

Batch Processing

Your Lambda handler will receive multiple order messages in a single invocation. Each order must be processed independently, and partial failures must be reported so that only failed messages are returned to the queue for retry.

Order Validation

Each order message contains JSON data with the following fields:

  • order_id (string): Unique order identifier
  • customer_id (string): Customer identifier
  • items (array): List of items being ordered
  • total_amount (number): Total order amount

The function should:

  • Parse and validate each order message
  • Skip processing for orders where total_amount is less than 0 (treat as validation failure)
  • Skip processing for orders where items array is empty (treat as validation failure)

Processing Logic

For valid orders:

  1. Print a log message: "Processing order {order_id} for customer {customer_id}"
  2. Simulate processing by checking if order_id contains the string "fail" (case-insensitive)
    • If it contains "fail", raise an exception to simulate a processing error
    • Otherwise, consider the order successfully processed

Test Cases

  • When given a batch with one valid order (order_id="ORD-001", customer_id="CUST-123", items=["item1"], total_amount=99.99), it processes successfully and returns no failures @test
  • When given a batch with one order containing negative total_amount, it skips the order and reports it as failed @test
  • When given a batch with one order containing empty items array, it skips the order and reports it as failed @test
  • When given a batch with mixed valid and invalid orders, it processes valid ones and reports only invalid ones as failed @test
  • When given a batch where an order_id contains "FAIL", it catches the exception and reports that order as failed @test

Implementation

@generates

API

def lambda_handler(event: dict, context) -> dict:
    """
    Lambda handler that processes SQS order messages with partial failure handling.

    Args:
        event: Lambda event containing SQS records
        context: Lambda context object

    Returns:
        dict with batchItemFailures for messages that failed processing
    """
    pass

def process_order(order_data: dict) -> None:
    """
    Process a single order after validation.

    Args:
        order_data: Parsed order data dictionary

    Raises:
        Exception: If order processing fails
    """
    pass

Dependencies { .dependencies }

aws-lambda-powertools { .dependency }

Provides utilities for AWS Lambda best practices including batch processing with partial failure handling.

@satisfied-by