Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

python - Create a loop with aws credentials - Boto3

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...