繁体   English   中英

boto3定价返回相同类型实例的多个值

[英]boto3 pricing returns multiple values for same type of instances

我正在尝试以下代码来获取我所在地区的实例价格:

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"]

上面代码的输出是:

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

我想做什么

我正在尝试获取实例类型的价格值,以便可以使用boto3实例组出价一半的价格。

我的观察

除SKU和输出中显示的参数外,所有参数均匹配。 其中之一有一个预留字段,我想这也是已预留实例的字段。

>>> json.loads(pricingValues["PriceList"][1])["terms"].keys()
[u'Reserved', u'OnDemand']

我的困惑是什么

我总是获得3个价格值,无论选择哪种实例类型,这都是事实。我想了解这些是什么,为什么其中一个报告的价格是0.0美元。

我找不到有关这些值的任何文档,但我的猜测是:

  • Used :按需使用实例的成本
  • UnusedCapacityReservation :未使用预留实例的成本(您仍需为之付费)
  • AllocatedCapacityReservation :实例的成本(如果实例用作预留实例)(已付费,因此没有成本)

这些只是我的猜测。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM