Demonstrate BatchGetItem.
(client)
| 378 | # --------------------------------------------------------------------------- |
| 379 | |
| 380 | def batch_operations(client) -> None: |
| 381 | """Demonstrate BatchGetItem.""" |
| 382 | section("Step 6: Batch Operations (BatchGetItem)") |
| 383 | |
| 384 | resp = client.batch_get_item( |
| 385 | RequestItems={ |
| 386 | USERS_TABLE: { |
| 387 | "Keys": [ |
| 388 | {"userId": {"S": "user-001"}}, |
| 389 | {"userId": {"S": "user-002"}}, |
| 390 | {"userId": {"S": "user-003"}}, |
| 391 | ], |
| 392 | }, |
| 393 | }, |
| 394 | ) |
| 395 | users = resp["Responses"][USERS_TABLE] |
| 396 | print(f" ✓ BatchGetItem returned {len(users)} users:") |
| 397 | for u in sorted(users, key=lambda x: x["userId"]["S"]): |
| 398 | print(f" {u['userId']['S']}: {u['name']['S']} ({u['email']['S']})") |
| 399 | # --------------------------------------------------------------------------- |
| 400 | # Step 7: Transactions |
| 401 | # --------------------------------------------------------------------------- |