boto3定价为相同类型的实例返回多个值 [英] boto3 pricing returns multiple values for same type of instances

查看:189
本文介绍了boto3定价为相同类型的实例返回多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

以上代码的输出为:

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实例组竞标价格的一半.

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.

我的观察

除SKU和输出中显示的参数外,所有参数均匹配. 其中之一有一个保留"字段,我想这也适用于已保留的实例.

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

我的困惑

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

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.

推荐答案

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

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

  • Used:按需使用实例的成本
  • UnusedCapacityReservation:未使用预留实例的成本(您仍需支付)
  • AllocatedCapacityReservation:如果实例被用作预留实例,则该实例的成本(已付费,因此没有成本)
  • 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)

这些只是我的猜测.

这篇关于boto3定价为相同类型的实例返回多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆