Abdelouahab Pp
Abdelouahab Pp

Reputation: 4440

how to get amazon prices using Boto?

it seems that Boto is the official Amazon API module for Python, and this one is for Tornado, so here is my questions:

Upvotes: 0

Views: 641

Answers (1)

Jess
Jess

Reputation: 116

generally, pagination is performed by the client requesting the api. To do this in boto, you'll need to cut your systems up. So for instance, say you make a call to AWS via boto, using the get_all_instances def; you'll need to store those somehow and then keep track of which servers have been displayed, and which not. To my knowledge, boto does not have the LIMIT functionality most dev's are used to from MySQL. Personally, I scan all my instances and stash them in mongo like so:

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)

You could also wrap these in try/catch blocks. Up to you. Once you get them out of boto, should be trivial to do the cut up work.

-- Jess

Upvotes: 3

Related Questions