Skip to content

Comments

docs: fix map operation examples to return JSON-serializable dict#309

Closed
abhu85 wants to merge 1 commit intoaws:mainfrom
abhu85:docs/fix-map-examples-301
Closed

docs: fix map operation examples to return JSON-serializable dict#309
abhu85 wants to merge 1 commit intoaws:mainfrom
abhu85:docs/fix-map-examples-301

Conversation

@abhu85
Copy link
Contributor

@abhu85 abhu85 commented Feb 20, 2026

Summary

Fixes #301

The map operation documentation examples were returning BatchResult directly from Lambda handlers. Since BatchResult is not JSON serializable, these examples would cause Lambda to fail at runtime with serialization errors.

Changes

  • Update all 7 handler return types from BatchResult[T] to dict
  • Add .to_dict() calls to convert BatchResult before returning
  • Add explanatory comments about JSON serialization requirement
  • Update "Getting started" section description to reflect the dict return type
  • Keep one example (check_inventory) showing how to extract and transform results from BatchResult before returning

Before

@durable_execution
def handler(event: dict, context: DurableContext) -> BatchResult[int]:
    items = [1, 2, 3, 4, 5]
    result = context.map(items, square)
    return result  # Fails: BatchResult is not JSON serializable

After

@durable_execution
def handler(event: dict, context: DurableContext) -> dict:
    """Process a list of items using map operations."""
    items = [1, 2, 3, 4, 5]
    result = context.map(items, square)
    # Convert to dict for JSON serialization (BatchResult is not JSON serializable)
    return result.to_dict()

Test plan

  • Verified all 7 map operation handler examples now return dict type
  • Verified all handlers use .to_dict() for BatchResult conversion
  • Verified the API signature section (context.map() returns BatchResult[T]) is unchanged (correct behavior)
  • Verified the "Filtering and transforming results" example shows proper result extraction pattern

Generated with Claude Code

Fix issue aws#301: Map operation examples were returning BatchResult
directly, which is not JSON serializable and causes Lambda to fail.

Changes:
- Update all handler return types from BatchResult[T] to dict
- Add .to_dict() calls to convert BatchResult before returning
- Add explanatory comments about JSON serialization requirement
- Update "Getting started" description to reflect dict return type
- Keep one example showing how to extract and filter results

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@yaythomas
Copy link
Member

incorporated in this PR #312

I kept the author info on the commit, so you're credited @abhu85

@yaythomas yaythomas closed this Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Docs]: Map operations examples in the documentation is not working

2 participants