Skip to content

Instantly share code, notes, and snippets.

@Burekasim
Created June 1, 2021 21:58
Show Gist options
  • Save Burekasim/3d7230ad56e98f2fce0b2476dcbbe4d3 to your computer and use it in GitHub Desktop.
Save Burekasim/3d7230ad56e98f2fce0b2476dcbbe4d3 to your computer and use it in GitHub Desktop.
search for 3rd party RI
import boto3
import datetime
def display_reserved(region, res):
if res:
if 'ReservedInstancesOfferings' in res:
for item in res['ReservedInstancesOfferings']:
if item['Marketplace']:
if item['Duration'] <= 7888000:
duration = datetime.timedelta(seconds=item['Duration'])
fixed_price = item['FixedPrice']
instance_type = item['InstanceType']
count = item['PricingDetails'][0]['Count']
recurring_charge_amount = item['RecurringCharges'][0]['Amount']
print(
f'Region: {region}, Found {count}, instance type {instance_type}, duration {duration}, upfront price: {fixed_price}, hourly cost {recurring_charge_amount}')
if __name__ == '__main__':
region_name = 'us-east-1'
regions_list = [region['RegionName'] for region in
boto3.client('ec2', region_name='us-east-1').describe_regions()['Regions']]
# for region in regions_list:
client = boto3.client('ec2', region_name='us-east-1')
response = client.describe_reserved_instances_offerings(ProductDescription='Linux/UNIX (Amazon VPC)', IncludeMarketplace=True)
display_reserved(region_name, response)
while response:
response = client.describe_reserved_instances_offerings(ProductDescription='Linux/UNIX (Amazon VPC)',
IncludeMarketplace=True,
NextToken=response[
'NextToken']) if 'NextToken' in response else None
display_reserved(region_name, response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment