问题描述
我将 aws ec2 服务与 awscli 一起使用.现在我想将我在控制台中键入的所有命令放入一个 python 脚本中.我看到如果我在 python 脚本中编写 import awscli
它工作正常,但我不明白如何在脚本中使用它.例如,如何在 import awscli
之后在 python 脚本中执行命令 aws ec2 run-instances
?为了清楚起见,我不是在寻找像 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!