簡體   English   中英

在Python中切換AWS賬戶

[英]Switching AWS Accounts in Python

使用AWS CLI時,它引用位於〜/ .aws目錄中的憑證和配置文件。 然后,您使用--profile標志來指示所需的帳戶。 如:

aws ec2 describe-instances --profile=company-lab
aws ec2 describe-instances --profile=company-nonprod 

等等

但是我是python 3和boto 3腳本編寫的新手,並且想在那里做同樣的事情。 如何使用python在AWS賬戶之間切換?

創建會話對象時只需使用`profile_nameˋ參數。

session = boto3.Session(profile_name='dev')
# Any clients created from this session will use credentials
# from the [dev] section of ~/.aws/credentials.
dev_s3_client = session.client('s3')

https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM