如何从Boto获取当前用户的区域? [英] How to get the region of the current user from boto?

查看:192
本文介绍了如何从Boto获取当前用户的区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

我正在尝试从boto3获取经过身份验证的用户所在的区域。

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

用例:

我正在努力将缓存添加到 https://github.com/pmazurek/aws-fuzzy-finder 。我宁愿按每个区域缓存结果。

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.

此包使用boto获取用户身份验证数据(密钥和区域) 。问题在于该区域永远不会被用户明确地通过,它是从boto读取的许多阴暗的地方之一拿走的,所以我真的没有办法得到它。

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.

我尝试通过boto3 api搜索和谷歌搜索,但是找不到类似 get_region get_user_data 方法。

I have tried searching through boto3 api and googling, but couldn't find anything like a get_region or get_user_data method. Is it possible?

推荐答案

您应该能够阅读 region_name $ c> session.Session 对象,如

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 基本上定义为 session.get_config_variable('region')

这篇关于如何从Boto获取当前用户的区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆