I'm trying to create a loop to switch for each account on ~/.aws/credentials, my aws credentials has 64 accounts, for each one i want to list all buckets.
# !/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 Credentials example:
[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
question from:
https://stackoverflow.com/questions/66052205/create-a-loop-with-aws-credentials-boto3 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…