python - boto.ec2.connection.EC2Connection.request_spot_instances() 不返回 boto.ec2.spotinstancerequest.SpotInstanceRequest

标签 python amazon-web-services amazon-ec2 boto

标题已经说明问题了。

我正在请求一个带有 boto 的 Spot 实例,如下所示(aws key 和 secret key 是 ~/.boto 中设置的环境变量):

import boto
conn = boto.connect_ec2()
type(conn)
> boto.ec2.connection.EC2Connection

response = conn.request_spot_instances(**params)
type(response)
> boto.resultset.ResultSet

params 具有价格、image_id、instance_type 和展示位置的值。

这是该库与其文档不同的地方。正如您在 boto docs 中看到的那样,request_spot_instances() 应该返回 boto.ec2.spotinstancerequest.SpotInstanceRequest,但它返回 boto.resultset.ResultSet

没有方法可以获取 boto.resultset.ResultSet 的请求 id,这正是我真正想要的。我不想解析从打印响应返回的值,但我在文档中找不到获取它的好方法。

print(response)
> [SpotInstanceRequest:sir-xxxxxxx]

最佳答案

好吧,这不再是问题了

In [120]: type(response[0])
Out[120]: boto.ec2.spotinstancerequest.SpotInstanceRequest

您只需引用列表的第一个对象。不过,我觉得应该更新文档以反射(reflect)该函数返回包含 SpotInstanceRequest

的列表

关于python - boto.ec2.connection.EC2Connection.request_spot_instances() 不返回 boto.ec2.spotinstancerequest.SpotInstanceRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28307230/

相关文章:

python - 如何使用 openpyxl 在 XLSX 文件中逐个单元格地插入和格式化值

python - Flask官方教程: what is 'e' in close_db(e=None)?

python - 如何根据 Python 中的两个条件更改列的值

python - 消费者之后的 RabbitMQ 清理

amazon-web-services - AWS 负载均衡器不安全

amazon-web-services - 在 bash 中使用 ec2 命令行工具获取 ec2 实例的公共(public) dns 名称

amazon-web-services - 与您的团队共享您的 elasticbeanstalk 配置的正确方法是什么?

amazon-web-services - 如何在没有 AWS 的情况下在私有(private)网络中运行 Amazon Echo

amazon-web-services - 在 Elastic Beanstalk Linux Tomcat 8 上将 http 重定向到 https

php - shell_exec 未针对 php 中的特定代码运行