AWS lambda documentation change
Summary
Updated Python code example for durable function execution: added helper functions, type hints, improved activity naming, and enhanced result tracking.
Security assessment
The changes focus on code clarity and SDK usage improvements without introducing security features or addressing vulnerabilities. The added functions (validate_order, request_approval, complete_order) demonstrate business logic patterns, not security controls. The timeout configuration remains functionally equivalent.
Diff
diff --git a/lambda/latest/dg/durable-invoking-esm.md b/lambda/latest/dg/durable-invoking-esm.md index 41cf944b7..3b4adf899 100644 --- a//lambda/latest/dg/durable-invoking-esm.md +++ b//lambda/latest/dg/durable-invoking-esm.md @@ -192,0 +193,2 @@ Python + from aws_durable_execution_sdk_python.config import Duration, WaitForCallbackConfig + from collections.abc import Sequence @@ -194,0 +197,12 @@ Python + def validate_order(order_data: dict) -> dict: + """Validate order data - always passes.""" + return order_data + + def request_approval(callback_id: str, validated_order: dict) -> None: + """Request approval for the order - always passes.""" + pass + + def complete_order(validated_order: dict, approval_result: str) -> dict: + """Complete the order processing - always passes.""" + return validated_order + @@ -196 +210 @@ Python - def handler(payload, context: DurableContext): + def lambda_handler(payload, context: DurableContext): @@ -199,2 +213,6 @@ Python - # Process each record with complex, multi-step logic - def process_record(ctx, record): + def process_record( + ctx: DurableContext, + record: dict, + index: int, + items: Sequence[dict] + ) -> dict: @@ -203 +221 @@ Python - name='validate' + name=f'validate-{index}' @@ -206 +223,0 @@ Python - # Wait for external approval (could take hours or days) @@ -208,3 +225,3 @@ Python - lambda callback_id: request_approval(callback_id, validated), - name='approval', - config=WaitForCallbackConfig(timeout_seconds=172800) # 48 hours + submitter=lambda callback_id, wait_ctx: request_approval(callback_id, validated), + name=f'approval-{index}', + config=WaitForCallbackConfig(timeout=Duration.from_seconds(172800)) @@ -213 +229,0 @@ Python - # Complete processing @@ -216 +232 @@ Python - name='complete' + name=f'complete-{index}' @@ -219 +235,5 @@ Python - results = context.map(sqs_event['Records'], process_record) + results = context.map( + inputs=sqs_event['Records'], + func=process_record, + name='process-records' + ) @@ -221 +241,7 @@ Python - return {'statusCode': 200, 'processed': len(results.get_results())} + return { + 'statusCode': 200, + 'started': results.started_count, + 'completed': results.success_count, + 'failed': results.failure_count, + 'total': results.total_count + }