boto3 pricing returns multiple values for same type of instances

不打扰是莪最后的温柔 提交于 2019-12-25 00:10:02

问题


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.


回答1:


I couldn't find any documentation on those values, but my guess would be:

  • Used: The cost of using the instance On-Demand
  • UnusedCapacityReservation: 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.



来源:https://stackoverflow.com/questions/55122776/boto3-pricing-returns-multiple-values-for-same-type-of-instances

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!