新規 – AWS 料金表 API に記載されている元の AWS 料金表が、構造化された URL を使用して JSON 形式と CSV 形式で料金にアクセスできるようになりました。これはいくつかの種類のコスト管理ツールでうまく機能しましたが、そのファイルのサイズと複雑さのためダウンロードが困難で、解析が面倒でした。今回は API を更新し、新しい関数を追加して必要な料金だけを返すきめ細かな料金クエリを実行できるようにしました。これにより、モバイルおよびブラウザベースのアプリケーションで料金表を利用することができるようになります。
新しい関数
新しい関数は以下のとおりです。
DescribeServices
– サービス内の製品を定義するために使用される属性キーのセットを返します。たとえば、EC2 に返されるキーには、physicalProcessor、memory、operatingSystem、location、tenancy があります。
GetAttributeValues
– 指定された属性キーのすべての許容値を返します。たとえば、operatingSystem キーの値には、Windows、RHEL、Linux、SUSE があり、location キーの値には米国東部 (バージニア北部) とアジアパシフィック (ムンバイ) があります。
GetProducts
– サービス名と属性値に基づくフィルタ式に一致する、すべての製品を公表価格とともに返します。
これらの関数には、AWS SDK からアクセスできます。それらを試してみるために、私は Python と AWS SDK for Python を使用しました。まず、SDK をインポートしてクライアントを作成するところから始めます。
import boto3
import json
import pprint
pricing = boto3.client('pricing')
すべてのサービスと属性を一覧表示する方法は次のとおりです。
print("All Services")
print("============")
response = pricing.describe_services()
for service in response['Services']:
print(service['ServiceCode'] + ": " + ", ".join(service['AttributeNames']))
print()
出力は次のようになります。
All Services
============
SnowballExtraDays: productFamily, termType, usagetype, locationType, snowballType, feeDescription, servicecode, feeCode, location, operation
OpsWorks: productFamily, servicecode, termType, usagetype, locationType, location, operation, serverLocation, group
mobileanalytics: productFamily, servicecode, includedEvents, termType, usagetype, description, locationType, location, operation
IngestionServiceSnowball: productFamily, fromLocationType, termType, usagetype, locationType, toLocationType, toLocation, snowballType, servicecode, groupDescription, transferType, location, fromLocation, operation, group
IngestionService: productFamily, termType, usagetype, locationType, servicecode, groupDescription, dataAction, location, operation, group
ElasticMapReduce: productFamily, softwareType, instanceType, termType, usagetype, locationType, instanceFamily, servicecode, location, servicename, operation
datapipeline: productFamily, frequencyMode, termType, usagetype, locationType, description, executionFrequency, servicecode, location, operation, group, executionLocation
...
EC2 のすべての料金属性の値をすべて取得する方法は次のとおりです。
print("Selected EC2 Attributes & Values")
print("================================")
response = pricing.describe_services(ServiceCode='AmazonEC2')
attrs = response['Services'][0]['AttributeNames']
for attr in attrs:
response = pricing.get_attribute_values(ServiceCode='AmazonEC2', AttributeName=attr)
values = []
for attr_value in response['AttributeValues']:
values.append(attr_value['Value'])
print(" " + attr + ": " + ", ".join(values))
出力は次のようになります。
Selected EC2 Attributes & Values
================================
volumeType: Throughput Optimized HDD, Provisioned IOPS, Magnetic, General Purpose, Cold HDD
maxIopsvolume: 500 - based on 1 MiB I/O size, 40 - 200, 250 - based on 1 MiB I/O size, 20000, 10000
instanceCapacity10xlarge: 1
locationType: AWS Region
instanceFamily: Storage optimized, Micro instances, Memory optimized, GPU instance, General purpose, Compute optimized
operatingSystem: Windows, SUSE, RHEL, NA, Linux
...
そして、ここでは、サービス名と属性値を使用して、64 の vCPU、256 GiB のメモリ、あらかじめインストールされた SQL Server Enterprise を持つ EC2 インスタンスのアジアパシフィック (ムンバイ) リージョンにおける料金表の取得方法を示します。各料金は JSON 文字列です。
print("Selected EC2 Products")
print("=====================")
response = pricing.get_products(
ServiceCode='AmazonEC2',
Filters = [
{'Type' :'TERM_MATCH', 'Field':'operatingSystem', 'Value':'Windows' },
{'Type' :'TERM_MATCH', 'Field':'vcpu', 'Value':'64' },
{'Type' :'TERM_MATCH', 'Field':'memory', 'Value':'256 GiB' },
{'Type' :'TERM_MATCH', 'Field':'preInstalledSw', 'Value':'SQL Ent' },
{'Type' :'TERM_MATCH', 'Field':'location', 'Value':'Asia Pacific (Mumbai)'}
],
MaxResults=100
)
for price in response['PriceList']:
pp = pprint.PrettyPrinter(indent=1. width=300)
pp.pprint(json.loads(price))
print()
出力は次のようになります (その他多数)。
Selected EC2 Products
=====================
{'product': {'attributes': {'clockSpeed': '2.3 GHz',
'currentGeneration': 'Yes',
'dedicatedEbsThroughput': '10000 Mbps',
'ecu': '188',
'enhancedNetworkingSupported': 'Yes',
'instanceFamily': 'General purpose',
'instanceType': 'm4.16xlarge',
'licenseModel': 'No License required',
'location': 'Asia Pacific (Mumbai)',
'locationType': 'AWS Region',
'memory': '256 GiB',
'networkPerformance': '20 Gigabit',
'normalizationSizeFactor': '128',
'operatingSystem': 'Windows',
'operation': 'RunInstances:0102',
'physicalProcessor': 'Intel Xeon E5-2686 v4 (Broadwell)',
'preInstalledSw': 'SQL Ent',
'processorArchitecture': '64-bit',
'processorFeatures': 'Intel AVX, Intel AVX2, Intel Turbo',
'servicecode': 'AmazonEC2',
'servicename': 'Amazon Elastic Compute Cloud',
'storage': 'EBS only',
'tenancy': 'Shared',
'usagetype': 'APS3-BoxUsage:m4.16xlarge',
'vcpu': '64'},
'productFamily': 'Compute Instance',
'sku': '24GRA8RB2KZ9NPCS'},
'publicationDate': '2017-10-07T00:26:55Z',
'serviceCode': 'AmazonEC2',
...
レスポンスの次の部分には、インスタンスを購入する特定の方法を説明する用語の配列が含まれています (オンデマンド またはさまざまなタイプのリザーブドインスタンス)。
'terms': {'OnDemand': {'24GRA8RB2KZ9NPCS.JRTCKXETXF': {'effectiveDate': '2017-09-01T00:00:00Z',
'offerTermCode': 'JRTCKXETXF',
'priceDimensions': {'24GRA8RB2KZ9NPCS.JRTCKXETXF.6YS6EN2CT7': {'appliesTo': [],
'beginRange': '0',
'description': '$30.88 per On Demand Windows with SQL Server Enterprise m4.16xlarge Instance Hour',
'endRange': 'Inf',
'pricePerUnit': {'USD': '30.8800000000'},
'rateCode': '24GRA8RB2KZ9NPCS.JRTCKXETXF.6YS6EN2CT7',
'unit': 'Hrs'}},
'sku': '24GRA8RB2KZ9NPCS',
'termAttributes': {}}},
'Reserved': {'24GRA8RB2KZ9NPCS.38NPMPTW36': {'effectiveDate': '2017-04-30T23:59:59Z',
'offerTermCode': '38NPMPTW36',
'priceDimensions': {'24GRA8RB2KZ9NPCS.38NPMPTW36.2TG2D8R56U': {'appliesTo': [], 'description': 'Upfront Fee', 'pricePerUnit': {'USD': '374227'}, 'rateCode': '24GRA8RB2KZ9NPCS.38NPMPTW36.2TG2D8R56U', 'unit': 'Quantity'},
'24GRA8RB2KZ9NPCS.38NPMPTW36.6YS6EN2CT7': {'appliesTo': [],
'beginRange': '0',
'description': 'Windows with SQL Server Enterprise (Amazon VPC), m4.16xlarge reserved instance applied',
'endRange': 'Inf',
'pricePerUnit': {'USD': '14.2400000000'},
'rateCode': '24GRA8RB2KZ9NPCS.38NPMPTW36.6YS6EN2CT7',
'unit': 'Hrs'}},
'sku': '24GRA8RB2KZ9NPCS',
'termAttributes': {'LeaseContractLength': '3yr', 'OfferingClass': 'standard', 'PurchaseOption': 'Partial Upfront'}},
...
これらの関数とそれらが返すデータの詳細については、「AWS の料金表 API の使用」を参照してください。
提供開始
新しい関数は今すぐご利用いただけます。現在、米国東部 (バージニア北部) および アジアパシフィック (ムンバイ) リージョンでこれらの関数を使用して、すべてのパブリック AWS リージョンおよび AWS GovCloud (US)のメタデータおよび料金表に無料でアクセスすることができます。
これらの関数を使用する方法の実際の例を見るには、「AWS マネジメントツールのブログ」の新しい投稿「Controlling Projected User Costs Through Monthly Budget Policies」を参照してください。
— Jeff;