Skip to content

Instantly share code, notes, and snippets.

@mvanholsteijn
Last active March 15, 2022 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvanholsteijn/3229f6760392763bd426ea264a47b9d2 to your computer and use it in GitHub Desktop.
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
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