Reputation: 13
I am trying the following code to get the prices of instances in my region:
import boto3
import json
my_session = boto3.session.Session()
region = boto3.session.Session().region_name
print "region : ",region
pricing_client = boto3.client("pricing")
pricingValues = pricing_client.get_products(ServiceCode='AmazonEC2',Filters=[{'Type': 'TERM_MATCH','Field': 'instanceType','Value': 'm4.large'},{'Type': 'TERM_MATCH','Field': 'location','Value': 'Asia Pacific (Mumbai)'},{'Type': 'TERM_MATCH','Field': 'operatingSystem','Value': 'Linux'},{'Type': 'TERM_MATCH','Field': 'preInstalledSw','Value': 'NA'},{'Type': 'TERM_MATCH','Field': 'tenancy','Value': 'Dedicated'}])
for priceVal in pricingValues["PriceList"]:
priceValInJson=json.loads(priceVal)
if("OnDemand" in priceValInJson["terms"] and len(priceValInJson["terms"]["OnDemand"]) > 0):
for onDemandValues in priceValInJson["terms"]["OnDemand"].keys():
for priceDimensionValues in priceValInJson["terms"]["OnDemand"][onDemandValues]["priceDimensions"]:
print "USDValue : ",priceValInJson["terms"]["OnDemand"][onDemandValues]["priceDimensions"][priceDimensionValues]["pricePerUnit"]," : ", priceValInJson["product"]["attributes"]["capacitystatus"]," : ", priceValInJson["product"]["attributes"]["usagetype"]
The output of the above code is:
region : ap-south-1
USDValue : {u'USD': u'0.0000000000'} : AllocatedCapacityReservation : APS3-DedicatedRes:m4.large
USDValue : {u'USD': u'0.1155000000'} : Used : APS3-DedicatedUsage:m4.large
USDValue : {u'USD': u'0.1155000000'} : UnusedCapacityReservation : APS3-UnusedDed:m4.large
What I am trying to do
I am trying to get the price value of the instance type so that i can bid for half the price using boto3 instance groups.
My Observation
All the parameters match except for SKU and the ones displayed in output. One of them has a Reserved field also which I guess is for the instances that have been reserved.
>>> json.loads(pricingValues["PriceList"][1])["terms"].keys()
[u'Reserved', u'OnDemand']
What my confusion is
I always get 3 values for the prices.This is true no matter what instance type I choose.I would like to understand what these are and why one of the reported price is 0.0 USD.
Upvotes: 0
Views: 1129
Reputation: 269101
I couldn't find any documentation on those values, but my guess would be:
Used
: The cost of using the instance On-DemandUnusedCapacityReservation
: The cost of a Reserved Instance when it isn't being used (you still pay for it)AllocatedCapacityReservation
: The cost of an instance if it is being used as a Reserved Instance (already paid for, therefore no cost)Those are just my guesses.
Upvotes: 2