Last active
March 15, 2022 07:48
-
-
Save mvanholsteijn/3229f6760392763bd426ea264a47b9d2 to your computer and use it in GitHub Desktop.
Inspects the Python call stack searching for a specific object type performing this call
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import botocore | |
from typing import Optional | |
def get_boto_caller_client_meta() -> Optional[botocore.client.ClientMeta]: | |
""" | |
returns the ClientMeta of the boto calling boto client. | |
""" | |
for frame in map(lambda f: f.frame, inspect.stack()): | |
s = frame.f_locals.get('self') | |
if s and hasattr(s, "meta") and isinstance(s.meta, botocore.client.ClientMeta): | |
return s.meta | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment