[英]looping over multiple aws profiles with boto3
我似乎無法找到一個非常好的方法來啟動與boto3的多個會話。 如果我有10個帳戶並想讓我們說,創建一個新的IAM用戶,我似乎無法用新的調用更改boto3.session.Session。
示例代碼:
for user in usernames:
for acct in accounts:
boto3.session.Session(profile_name=acct)
print 'trying account: %s' % acct
try:
uname = IAM.create_user(UserName=user)
uname
print uname
print row_template % header
print row_template % tuple(['-' * len(h) for h in header])
print row_template % (user, acct)
except botocore.exceptions.ClientError as e:
print e
但是,它只會為默認會話創建一個會話,並且不會更改它。 我似乎無法找到一種方法來關閉會話。
任何幫助將不勝感激。
您沒有使用boto3.session()返回的會話。 而是使用相同的默認會話。 您可以從以下代碼段開發:
for acct in accounts:
session = boto3.Session(profile_name=acct)
iam = session.client('iam')
for user in usernames:
iam.create_user(UserName=user)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.