Skip to content

Instantly share code, notes, and snippets.

@jlintz
Created April 21, 2016 14:20
Show Gist options
  • Save jlintz/aed4929682aa35c859c28328da76f9ec to your computer and use it in GitHub Desktop.
Save jlintz/aed4929682aa35c859c28328da76f9ec to your computer and use it in GitHub Desktop.
from boto import connect_ec2
def get_ri_costs(connection):
"""
@connection: EC2Connection obj
returns: list
"""
ri_costs = []
ris = connection.get_all_reserved_instances_offerings(include_marketplace=False,
product_description='Linux/UNIX')
token = getattr(ris, 'nextToken', None)
ri_costs.append(ris)
# results are paginated
while token:
ris = connection.get_all_reserved_instances_offerings(include_marketplace=False,
product_description='Linux/UNIX', next_token=token)
ri_costs.append(ris)
token = getattr(ris, 'nextToken', None)
# flatten list of lists into one list
ri_costs = sum(ri_costs, [])
return ri_costs
conn = connect_ec2()
ris = get_ri_costs(conn)
for a in ris:
if 'c4' in a.instance_type:
print a.pricing_details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment