[英]Create a loop with aws credentials - Boto3
我正在嘗試創建一個循環來為 ~/.aws/credentials 上的每個帳戶進行切換,我的 aws 憑據有 64 個帳戶,對於每個我想列出所有存儲桶的帳戶。
# !/usr/bin/env python
import os.path
import boto3
path = "~/.aws/credentials"
full_path = os.path.expanduser(path)
print(full_path)
with open(full_path, 'r') as f:
aws_account = f.read()
for account in aws_account:
s3 = boto3.client('s3')
response = s3.list_buckets()
buckets = [bucket['Name'] for bucket in response['Buckets']]
print("Bucket List: %s" % buckets)
AWS 憑證示例:
[TEST1]
aws_access_key_id = TEST1
aws_secret_access_key = TEST1
[TEST2]
aws_access_key_id = TEST2
aws_secret_access_key = TEST2
[TEST3]
aws_access_key_id = TEST3
aws_secret_access_key = TEST3
我就是這樣做的。
#!/usr/bin/python3
import os.path
path = "~/.aws/credentials"
full_path = os.path.expanduser(path)
aws_account = []
with open(full_path, 'r') as f:
lines = f.readlines()
f.close()
aws_account = [line[1:-2] for line in lines if line.startswith('[') ]
#print(aws_account)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.