【发布时间】:2017-11-24 17:39:13
【问题描述】:
我必须运行以下命令才能获得在 EC2 中运行我的 Python 脚本所需的所有“凭据”。所以我决定使用 subprocess 来简化这个过程。
subprocess.call(["export instance_profile=`curl
http://169.254.169.254/latest/meta-data/iam/security-credentials",
"export AWS_ACCESS_KEY_ID=`curl http://169.254.169.254/latest/meta-
data/iam/security-credentials/${instance_profile} | grep AccessKeyId
| cut -d':' -f2 | sed 's/[^0-9A-Z]*//g'`",
"export AWS_SECRET_ACCESS_KEY=`curl
http://169.254.169.254/latest/meta-data/iam/security-
credentials/${instance_profile} | grep SecretAccessKey | cut -d':' -
f2 | sed 's/[^0-9A-Za-z/+=]*//g'`",
"export AWS_SECURITY_TOKEN=`curl http://169.254.169.254/latest/meta-
data/iam/security-credentials/${instance_profile} | grep Token | cut
-d':' -f2 | sed 's/[^0-9A-Za-z/+=]*//g'`",
"export http_proxy=proxy.xxx.xxxxxxxxx.com:8099",
"export https_proxy=${http_proxy}"])
我得到一个错误:
File "funtest.py", line 25, in <module>
"export https_proxy=${http_proxy}"])
File "/usr/lib64/python2.7/subprocess.py", line 524, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib64/python2.7/subprocess.py", line 1327, in
_execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
我是 bash 和 subprocess 的新手,如果我的错误是微不足道的,请原谅我。我尝试运行 python ./script.py 但我有同样的错误。我想为此使用子进程,因为它被认为是最安全的方法。一些指导将不胜感激。
【问题讨论】:
标签: python bash shell amazon-web-services amazon-ec2