Intermittent `KeyError: 'credential_provider'` or `KeyError: 'endpoint_resolver'` when creating boto3 clients from many threads.
AdvancedTroubleshootingConcurrency, async, tests, services & containers
Answer
Likely causes → Clients created concurrently from the shared default session (boto3.client(...) inside worker threads). Session creation and component loading are not thread-safe.
Diagnose → The error appears only under concurrency and not in sequential runs.
Fix → Create one boto3.session.Session() per thread and build clients from it, or create the clients in the main thread before starting workers and share them (clients are thread-safe).
Prevent → Make "Session per thread" a team convention; our lab's audit_region does this.
More on Concurrency, async, tests, services & containers
`RuntimeError: asyncio.run() cannot be called from a running event loop` in a Jupyter notebook or inside an async framework.Intermediate`RuntimeWarning: coroutine 'fetch' was never awaited` and nothing happens.BeginnerAn asyncio health-checker is no faster than a sequential loop.Advanced`Task was destroyed but it is pending!` at shutdown.Advanced`OSError: [Errno 24] Too many open files` from an asyncio scanner with 20,000 targets.IntermediateA `ThreadPoolExecutor` job finishes "successfully" but half the work is missing, with no errors logged.Intermediate