[英]Switching AWS Accounts in Python
When using the AWS CLI it references the credentials and config files located in the ~/.aws directory. 使用AWS CLI时,它引用位于〜/ .aws目录中的凭证和配置文件。 And you use the --profile flag to indicate which account you want.
然后,您使用--profile标志来指示所需的帐户。 Such as:
如:
aws ec2 describe-instances --profile=company-lab
aws ec2 describe-instances --profile=company-nonprod
etc. 等等
But I am new to scripting in python 3 and boto 3 and want to do the same thing there. 但是我是python 3和boto 3脚本编写的新手,并且想在那里做同样的事情。 How can I switch between AWS accounts using python?
如何使用python在AWS账户之间切换?
Just use the `profile_nameˋ parameter when creating the session object. 创建会话对象时只需使用`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 https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.