简体   繁体   English

Boto3:配置文件位置

[英]Boto3: Configuration file location

有没有办法让 Boto 寻找默认位置以外的配置文件,即~/.aws

It's not clear from the question whether you are talking about boto or boto3.从问题中不清楚您是在谈论 boto 还是 boto3。 Both allow you to use environment variables to tell it where to look for credentials and configuration files but the environment variables are different.两者都允许您使用环境变量来告诉它在哪里查找凭据和配置文件,但环境变量是不同的。

In boto3 you can use the environment variable AWS_SHARED_CREDENTIALS_FILE to tell boto3 where your credentials file is (by default, it is in ~/.aws/credentials . You can use AWS_CONFIG_FILE to tell it where your config file is (by default, it is in ~/.aws/config .在 boto3 中,您可以使用环境变量AWS_SHARED_CREDENTIALS_FILE来告诉 boto3 您的凭证文件在哪里(默认情况下,它在~/.aws/credentials 。您可以使用AWS_CONFIG_FILE来告诉它您的配置文件在哪里(默认情况下,它在~/.aws/config

In boto, you can use BOTO_CONFIG to tell boto where to find its config file (by default it is in /etc/boto.cfg or ~/.boto .在 boto 中,您可以使用BOTO_CONFIG告诉 boto 在哪里可以找到它的配置文件(默认情况下它在/etc/boto.cfg~/.boto

Yes, you can install the configuration file (for site-wide settings that all users on this machine will use) in:是的,您可以在以下位置安装配置文件(用于此计算机上的所有用户都将使用的站点范围设置):

nano /etc/boto.cfg
[Credentials]
aws_access_key_id = your_key
aws_secret_access_key = your_password

Other possible locations could be:其他可能的位置可能是:

  • (if profile is given) ~/.aws/credentials for credentials shared between SDKs (如果提供了配置文件) ~/.aws/credentials用于 SDK 之间共享的凭据
  • (if profile is given) ~/.boto for user-specific settings (如果提供了配置文件) ~/.boto用于用户特定的设置
  • ~/.aws/credentials for credentials shared between SDKs ~/.aws/credentials用于 SDK 之间共享的凭据
  • ~/.boto for user-specific settings ~/.boto用于用户特定的设置

Yes, you can:是的你可以:

from boto3 documentation来自boto3 文档

  • Passing credentials as parameters in the boto.client() method在 boto.client() 方法中将凭据作为参数传递
  • Passing credentials as parameters when creating a Session object创建会话对象时将凭据作为参数传递
  • Environment variables环境变量
  • Shared credential file (~/.aws/credentials)共享凭证文件 (~/.aws/credentials)
  • AWS config file (~/.aws/config) AWS 配置文件 (~/.aws/config)
  • Assume Role provider承担角色提供者
  • Boto2 config file (/etc/boto.cfg and ~/.boto) Boto2 配置文件(/etc/boto.cfg 和 ~/.boto)
  • Instance metadata service on an Amazon EC2 instance that has an IAM role configured.已配置 IAM 角色的 Amazon EC2 实例上的实例元数据服务。

Please check the link for more information.请查看链接以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM