Interview Prep/Python for DevOps/Concurrency, async, tests, services & containers

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.

All Python for DevOps questions Roadmap: Python for automation

More on Concurrency, async, tests, services & containers