如何使用Boto获得亚马逊价格?

时间:2012-09-27 22:23:20

标签: amazon-web-services tornado boto

似乎Botoofficial Amazon API module for Pythonthis one is for Tornado,所以这是我的问题:

  • 它是否提供分页(仅请求10个产品,因为亚马逊每页提供10个产品,然后我只想获得第一页......),然后如何(示例代码?)
  • 如何解析产品解析,我使用python-amazon-simple-product-api但遗憾的是它不提供分页,所以所有优惠都在不断迭代。

1 个答案:

答案 0 :(得分:3)

通常,请求api的客户端执行分页。要在boto中执行此操作,您需要切断系统。例如,假设您通过boto使用get_all_instances def调用AWS;你需要以某种方式存储它们,然后跟踪哪些服务器已经显示,哪些服务器没有。据我所知,boto没有大多数开发人员习惯使用的LIMIT功能。就个人而言,我扫描所有实例并将它们藏在mongo中,如下所示:

for r in conn.get_all_instances():        # loop through all reservations
   groups = [g.name for g in r.groups]    # get a list of groups for this reservation
   for x in r.instances:                  # loop through all instances with-in reservation
      groups = ','.join(groups)         # join the groups into a comma separated list 
      name = x.tags.get('Name','');       # get instance name from the 'Name' tag

      new_record = { "tagname":name, "ip_address":x.private_ip_address, 
                      "external_ip_nat":x.ip_address, "type":x.instance_type,
                      "state":x.state, "base_image":x.image_id, "placement":x.placement, 
                      "public_ec2_dns":x.public_dns_name,
                      "launch_time":x.launch_time, "parent": ObjectId(account['_id'])}
      new_record['groups'] = groups
      systems_coll.update({'_id':x.id},{"$set":new_record},upsert=True)
      error = db.error()
      if error != None:
           print "err:%s:" % str(error)

您也可以将它们包装在try / catch块中。由你决定。一旦你把它们从博托那里拿出来,应该做一些微不足道的工作。

- 杰斯