简体   繁体   中英

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? 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. 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

More details here: http://boto.readthedocs.org/en/latest/boto_config_tut.html#introduction

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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