Getting Credentials File in the boto.cfg for Python

好久不见. 提交于 2019-12-07 16:23:53

问题


I'm using AWS for the first time and have just installed boto for python. I'm stuck at the step where it advices to:

"You can place this file either at /etc/boto.cfg for system-wide use or in the home directory of the user executing the commands as ~/.boto."

Honestly, I have no idea what to do. First, I can't find the boto.cfg and second I'm not sure which command to execute for the second option.

Also, when I deploy the application to my server, I'm assuming I need to do the same thing there too...


回答1:


"You can place this file either at /etc/boto.cfg for system-wide use or in the home directory of the user executing the commands as ~/.boto."

The former simply means that you might create a configuration file named boto.cfg within directory /etc (i.e. it won't necessarily be there already, depending on how boto has been installed on your particular system).

The latter is indeed phrased a bit unfortunate - ~/.boto means that boto will look for a configuration file named .boto within the home directory of the user executing the commands (i.e. Python scripts) which are facilitating the boto library.

You can read more about this in the boto wiki article BotoConfig, e.g. regarding the question at hand:

A boto config file is simply a .ini format configuration file that specifies values for options that control the behavior of the boto library. Upon startup, the boto library looks for configuration files in the following locations and in the following order:

  1. /etc/boto.cfg - for site-wide settings that all users on this machine will use
  2. ~/.boto - for user-specific settings

You'll indeed need to prepare a respective configuration file on the server your application is deployed to as well.

Good luck!




回答2:


For those who want to configure the credentials in Windows:

1-Create your file with the name you want(e.g boto_config.cfg) and place it in a location of your choice(e.g C:\Users\\configs).

2- Create an environment variable with the Name='BOTO_CONFIG' and Value= file_location/file_name

3- Boto is now ready to work with credentials automatically configured!

  • To create environment variables in Windows follow this tutorial: http://www.onlinehowto.net/Tutorials/Windows-7/Creating-System-Environment-Variables-in-Windows-7/1705



回答3:


For anyone looking for information on the now-current boto3, it does not use a separate configuration file but rather respects the default one created by the aws cli when running aws configure (Ie, it will look at ~/.aws/config)



来源:https://stackoverflow.com/questions/9197385/getting-credentials-file-in-the-boto-cfg-for-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!