我正在尝试使用AWS定价API来获取AWS EC2的价格,但是对于我给定的参数,我无法获得它。
我查找了要约文件并使用它可以搜索它,但是当我使用api时我无法搜索该组合。
这是我的代码。
hourlyTermCode = 'JRTCKXETXF'
rateCode = '6YS6EN2CT7'
pricing = boto3.client('pricing', region_name='us-east-1')
response = pricing.get_products(
ServiceCode='AmazonEC2',
Filters=[
{'Type': 'TERM_MATCH', 'Field': 'operatingSystem', 'Value': 'Linux'},
{'Type': 'TERM_MATCH', 'Field': 'location', 'Value': 'US West (Oregon)'}
],
MaxResults=100
)
for price in response['PriceList']:
resp = json.loads(price)
product = resp['product']
terms = resp['terms']
sku = product['sku']
print product['productFamily']
if product['productFamily'] == 'Compute Instance':
print 'here1'
if str(product['attributes']['instanceType']) == str(amazon_instance_type) :
print 'here2'
if str(product['attributes']['location']) == 'US West (Oregon)':
print 'here3'
if str(product['attributes']['operatingSystem']) == 'Linux':
print 'here4'
if str(product['attributes']['preInstalledSw']) == 'NA':
print 'here5'
if str(product['attributes']['tenancy']) == 'Shared':
price = resp['terms']['OnDemand'][sku][sku + '.' + hourlyTermCode + '.' + rateCode]['pricePerUnit']['USD']
print price