如何在Python脚本中使用awscli? [英] How to use awscli inside python script?
问题描述
我将aws ec2服务与awscli一起使用。现在,我要将在控制台中键入的所有命令放入python脚本。我发现,如果我在python脚本中编写 import awscli
可以正常工作,但我不知道如何在脚本中使用它。例如,在 import awscli
之后,如何在python脚本中执行命令 aws ec2 run-instances< arguments>
?只是为了清楚起见,我不是在寻找像 os.system('aws ec2 run-instances< arguments>')
这样的解决方案,我在寻找像这样的
I'm using aws ec2 service with awscli. Now I want to put all the commands I type in the console into a python script. I see that if I write import awscli
inside a python script it works fine but I don't understand how to use it inside the script. For instance how do I execute the commands aws ec2 run-instances <arguments>
inside the python script after import awscli
? Just to make it clear, I'm not looking for a solution like os.system('aws ec2 run-instances <arguments>')
, I'm looking for something like
import awscli
awscli.ec2_run-instances(<arguments>)
推荐答案
CLI更适合于shell提示符,有关更好的python API,请检查Boto库。此示例显示了如何启动实例: http://boto.readthedocs.org/en/latest/ec2_tut.html
The CLI would be more suited for the shell prompt, for a better python API, check the boto library. This example shows how to launch an instance: http://boto.readthedocs.org/en/latest/ec2_tut.html
这篇关于如何在Python脚本中使用awscli?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!