建议使用多个AWS账户管理凭证的方法吗?
发布于 2021-01-29 18:58:46
管理多个Amazon Web Services(AWS)帐户的最佳方法是什么boto
?
我对正在使用的BotoConfig文件很熟悉。但是每个文件仅描述一个帐户…而且我正在与多个组织合作。出于所有常规的法律,财务和安全原因,这些帐户无法混合。
目前,我boto
每个帐户使用一个配置文件。例如:
~/.boto
默认账户~/.boto_clowncollege
用于“小丑学院”帐户~/.boto_razorassoc
用于“ razorassoc”帐户~/.boto_xyz
对于“ xyz”帐户
然后是这样的:
def boto_config_path(account=None):
"""
Given an account name, return the path to the corresponding boto
configuration file. If no account given, return the default config file.
"""
path = '~/.boto' + ('_' + account if account else '')
clean_path = os.path.abspath(os.path.expanduser(path))
if os.path.isfile(clean_path):
return clean_path
else:
errmsg = "cannot find boto config file {} for {}".format(clean_path, account)
raise ValueError(errmsg)
def aws_credentials(account=None):
"""
Return a tuple of AWS credentials (access key id and secret access key) for
the given account.
"""
try:
cfg = INIConfig(open(boto_config_path(account)))
return ( cfg.Credentials.aws_access_key_id, cfg.Credentials.aws_secret_access_key )
except Exception:
raise
conn = EC2Connection(*aws_credentials('razorassoc'))
是好还是坏?建议的改进?
关注者
0
被浏览
47
1 个回答