Skip to content

Instantly share code, notes, and snippets.

@reecestart
Created February 13, 2019 06:09
Show Gist options
  • Save reecestart/77e49342df1c9c3198dff621219b2807 to your computer and use it in GitHub Desktop.
Save reecestart/77e49342df1c9c3198dff621219b2807 to your computer and use it in GitHub Desktop.
Python script which uses the Pricing API to get the Instance Store details for each EC2 Instance Type
import ast
import boto3
from botocore.exceptions import ClientError
pricingclient = boto3.client('pricing', region_name='us-east-1')
paginator = pricingclient.get_paginator('get_attribute_values')
response_iterator = paginator.paginate(
ServiceCode='AmazonEC2',
AttributeName='instanceType',
PaginationConfig={
'MaxItems': 1000,
'PageSize': 100
}
)
InstanceTypes = []
for response in response_iterator:
AttributeValues = response['AttributeValues']
for AttributeValue in AttributeValues:
if ("." in AttributeValue['Value']):
InstanceTypes.append(AttributeValue['Value'])
InstanceTypesWithStorage = []
for InstanceType in InstanceTypes:
print("Checking Instance Type:" + str(InstanceType))
response = pricingclient.get_products(
ServiceCode='AmazonEC2',
Filters=[
{
'Type': 'TERM_MATCH',
'Field': 'instanceType',
'Value': InstanceType
},
]
)
PriceList = response['PriceList']
InstanceDict = ast.literal_eval(PriceList[0])
StorageType = InstanceDict['product']['attributes']['storage']
List1 = [InstanceType, StorageType]
print("Instance Type:" + str(InstanceType) + " has the following Storage:" + StorageType)
InstanceTypesWithStorage.append(List1)
print(InstanceTypesWithStorage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment