Piotr Mazurek Piotr Mazurek - 8 months ago 40
Python Question

How to get the region of the current user from boto?


I'm trying to get the region of the authenticated user from boto3.

Use case:

I'm working on adding cache to https://github.com/pmazurek/aws-fuzzy-finder. I would prefer to cache the result on per-region basis.

This package uses boto to get user authentication data (keys and the region). The problem is the region is never passed explicitly by the user, its being taken from one of the many murky places that boto reads so I don't really have a way of getting it.

I have tried searching through boto3 api and googling, but couldn't find anything like a

method. Is it possible?


You should be able to read the region_name from the session.Session object like

my_session = boto3.session.Session()
my_region = my_session.region_name

region_name is basically defined as session.get_config_variable('region')