Created
April 21, 2016 14:20
-
-
Save jlintz/aed4929682aa35c859c28328da76f9ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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