我必须运行以下命令才能获得在EC2中运行我的Python脚本所需的所有“凭据”。所以我决定使用子流程来简化这个过程。Python子进程AWS凭证shell脚本导致目录错误
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和如果我的错误一些小事子所以请原谅我。我试过运行python ./script.py但我有同样的错误。我想为此使用子进程,因为它应该是最安全的方式。一些指导将非常感激。