简体   繁体   English

如何在Boto中使用系统环境变量

[英]how to use system environment variables in boto

I have exported AWS ACCESS KEY and SECRET via the environment variables, is there way to use those variables in the boto script instead of writing them to a file on the system? 我已通过环境变量导出了AWS ACCESS KEY和SECRET,是否可以在boto脚本中使用这些变量,而不是将其写入系统上的文件中? I don't want to write the key and secret in any file on the remote server. 我不想在远程服务器上的任何文件中写入密钥和机密。

If by use you mean read them and feed them into boto: You don't need to do that. 如果你的意思是阅读它们,并将它们送入伯特:你不需要这么做。 Boto reads them, and in all calls which would usually expect the aws_access_key_id= and aws_secret_access_key= parameters, you just leave them out altogether. Boto会读取它们,并且在通常会期望aws_access_key_id=aws_secret_access_key=参数的所有调用中,只需将它们完全排除在外。 Hence a call like this would work without problems: 因此,这样的调用将毫无问题地工作:

# note that we don't pass any credentials here...

conn = boto.ec2.connect_to_region("eu-west-1")

Just be sure the environment variables are set correctly. 只要确保环境变量设置正确即可。 These are the correct names to use: 这些是要使用的正确名称:

AWS_ACCESS_KEY_ID , AWS_SECRET_ACCESS_KEY AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY

More details here: http://boto.readthedocs.org/en/latest/boto_config_tut.html#introduction 此处有更多详细信息: http : //boto.readthedocs.org/en/latest/boto_config_tut.html#introduction

Boto查找环境变量AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY ,如果环境中存在它们,它将使用它们。

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

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