APC 技術ブログ

株式会社エーピーコミュニケーションズの技術ブログです。

株式会社 エーピーコミュニケーションズの技術ブログです。

【AWS】【初心者向け】料金表データ取得 (AWS Price List Bulk API)

目次

はじめに

こんにちは、クラウド事業部の菅です。

前回、AWS Price List Query APIを使用して料金表データを取得しました。

techblog.ap-com.co.jp

今回は、AWS Price List Bulk APIを使用して料金表データを取得してみます。

AWS Price List Bulk API

概要

ブラウザなどから、料金表データファイルをダウンロードする方法です。
料金表データファイルはJSON形式とCSV形式に対応しています。

公式ドキュメントによると、次のような場合に向いている方法とされています。

  • AWS のサービスの製品情報や料金情報を大量に処理する
  • 一括処理など、 AWS のサービスで高スループットで製品および料金情報を処理する

AWS Price List Bulk APIでは、SavingsPlansの料金表データも取得できます。

docs.aws.amazon.com

AWS Price List Query API同様、AWS Price List Bulk APIもpricing.apiのエンドポイント経由で実行されます。
pricing.apiエンドポイントは限られたリージョンにしか存在しませんので、API実行時は以下の何れかのリージョンを指定する必要があります。

  • us-east-1
  • eu-central-1
  • ap-south-1

オンデマンド・リザーブドインスタンス

前回と同じく以下の料金表データを取得します。
また、料金表データファイルはCSV形式で取得します。

1. 料金表データファイル取得

料金表データファイルをダウンロードします。

オンデマンド・リザーブドインスタンスの料金表データファイルは以下の分類で管理されています。

  • リージョン
  • サービス
  • バージョン

料金表データファイルのダウンロードには、上記に加えてファイル形式(CSVまたはJSON)が必要となります。
※インスタンスタイプなどの条件は、料金表データファイルダウンロード後にファイル内のデータに対して指定します。

料金表データファイルは以下のURLからダウンロードできます。

https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/serviceCode/version/regionCode/index.format
  ※各項目には以下の値を設定します。
      serviceCode:AWSのサービスコード ※前回の記事を参照
      version:取得する料金表データのバージョン
     ※最新バージョンを取得する場合は「current」を指定
      古いバージョンを取得する場合は、公開されているバージョン一覧を以下URLから取得して指定
       https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/serviceCode/index.json
      regionCode:取得対象のリージョンコード
      format:取得するファイルの拡張子  ※「json」または「csv」を指定

以下URLから最新バージョンの料金表データファイルをダウンロードします。

https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/ap-northeast-3/index.csv

2. 料金表データ取得

料金表データファイルは、次のような構成となっていました。

PS C:\Users\user\Downloads> gc index.csv
"FormatVersion","v1.0"
"Disclaimer","This pricing list is for informational purposes only. All prices are subject to the additional terms included in the pricing pages on http://aws.amazon.com. All Free Tier prices are also subject to the terms included at https://aws.amazon.com/free/"
"Publication Date","2025-04-23T20:08:44Z"
"Version","20250423200844"
"OfferCode","AmazonEC2"
"SKU","OfferTermCode","RateCode","TermType",(省略)
"222WG8V3Z2QGFCV7","JRTCKXETXF","222WG8V3Z2QGFCV7.JRTCKXETXF.6YS6EN2CT7","OnDemand",(省略)
(以下、料金表データが続く)

※1~5行目に料金表データファイルの情報、6行目に項目名、7行目以降に料金表データが記載されている

また、ファイル内の項目は以下となっていました。

PS C:\Users\user\Downloads> $csv = gc index.csv | select -Skip 5 | ConvertFrom-Csv
PS C:\Users\user\Downloads> echo $csv | gm | ?{$_.MemberType -ne 'Method' } | fw -Property Name -Column 4


AvailabilityZone              CapacityStatus                ClassicNetworkingSupport      Clock Speed
Currency                      Current Generation            Dedicated EBS Throughput      ECU
EffectiveDate                 EndingRange                   Enhanced Networking Supported GPU
GPU Memory                    Group                         Group Description             Instance
Instance Capacity - 10xlarge  Instance Capacity - 12xlarge  Instance Capacity - 16xlarge  Instance Capacity - 18xlarge
Instance Capacity - 24xlarge  Instance Capacity - 2xlarge   Instance Capacity - 32xlarge  Instance Capacity - 4xlarge
Instance Capacity - 8xlarge   Instance Capacity - 9xlarge   Instance Capacity - large     Instance Capacity - medium
Instance Capacity - metal     Instance Capacity - xlarge    Instance Family               Instance Type
instanceSKU                   Intel AVX Available           Intel AVX2 Available          Intel Turbo Available
LeaseContractLength           License Model                 Location                      Location Type
MarketOption                  Max IOPS Burst Performance    Max IOPS/volume               Max throughput/volume
Max Volume Size               Memory                        Network Performance           Normalization Size Factor
OfferingClass                 OfferTermCode                 Operating System              operation
Physical Cores                Physical Processor            Pre Installed S/W             PriceDescription
PricePerUnit                  Processor Architecture        Processor Features            Product Family
Product Type                  Provisioned                   PurchaseOption                RateCode
Region Code                   RelatedTo                     Resource Type                 serviceCode
serviceName                   SKU                           SnapshotArchiveFeeType        StartingRange
Storage                       Storage Media                 Tenancy                       TermType
To Location                   To Region Code                Unit                          usageType
vCPU                          Volume API Name               Volume Type                   VPCNetworkingSupport

※AWS Price List Query APIと似ていますが、項目名に大文字/小文字やスペースの有無などの違いがあります。
 また、CurrencyやebsOptimizedなど、どちらかにしかない項目もあります。

オンデマンド料金とリザーブドインスタンス料金を表示してみます。

PS C:\Users\user\Downloads> echo $csv |
>> ?{
>>     $_.'Operating System' -eq 'Windows' -and
>>     $_.'Pre Installed S/W' -eq 'SQL Std' -and
>>     $_.Tenancy -eq 'Shared' -and
>>     $_.'Instance Type' -eq 't3.xlarge' -and
>>     $_.'License Model' -eq 'No License required' -and
>>     $_.CapacityStatus -eq 'Used' -and
>>     $_.TermType -eq 'Ondemand'
>> } |
>> select PricePerUnit, Currency

PricePerUnit Currency
------------ --------
0.7712000000 USD


PS C:\Users\user\Downloads> echo $csv |
>> ?{
>>     $_.'Operating System' -eq 'Windows' -and
>>     $_.'Pre Installed S/W' -eq 'SQL Std' -and
>>     $_.Tenancy -eq 'Shared' -and
>>     $_.'Instance Type' -eq 't3.xlarge' -and
>>     $_.'License Model' -eq 'No License required' -and
>>     $_.TermType -eq 'Reserved' -and
>>     $_.LeaseContractLength -eq '1yr' -and
>>     $_.PurchaseOption -eq 'No Upfront' -and
>>     $_.OfferingClass -eq 'standard'
>> } |
>> select PricePerUnit, Currency

PricePerUnit Currency
------------ --------
0.6907000000 USD

料金表データファイルから金額が取得できました!
料金表ページの金額とも一致しています。

複数データの表示

料金表データをまとめて取得しているため、複数の値を並べて表示することも簡単にできます。
例えば、上記と同じ条件でオンデマンド料金一覧をインスタンスタイプ別に表示することができます。

PS C:\Users\user\Downloads> echo $csv |
>> ?{
>>     $_.'Operating System' -eq 'Windows' -and
>>     $_.'Pre Installed S/W' -eq 'SQL Std' -and
>>     $_.Tenancy -eq 'Shared' -and
>>     $_.'License Model' -eq 'No License required' -and
>>     $_.CapacityStatus -eq 'Used' -and
>>     $_.TermType -eq 'Ondemand'
>> } |
>> sort 'Instance Family', {$_.'Instance Type' -Replace '\..*$'}, {[Int]$_.vCPU}, {[Double]($_.Memory -Replace '\s.*$')}, 'Instance Type' |
>> select 'Instance Family', 'Instance Type', vCPU, Memory, PricePerUnit, Currency |
>> ft

Instance Family   Instance Type    vCPU Memory    PricePerUnit   Currency
---------------   -------------    ---- ------    ------------   --------
Compute optimized c4.large         2    3.75 GiB  1.3450000000   USD
Compute optimized c4.xlarge        4    7.5 GiB   1.5630000000   USD
Compute optimized c4.2xlarge       8    15 GiB    3.1250000000   USD
Compute optimized c4.4xlarge       16   30 GiB    6.2500000000   USD
Compute optimized c4.8xlarge       36   60 GiB    13.8100000000  USD
Compute optimized c5.large         2    4 GiB     0.6790000000   USD
(省略)
Compute optimized c6in.metal       128  256 GiB   30.3808000000  USD
General purpose   m4.large         2    8 GiB     0.7010000000   USD
General purpose   m4.xlarge        4    16 GiB    0.9220000000   USD
General purpose   m4.2xlarge       8    32 GiB    1.8440000000   USD
General purpose   m4.4xlarge       16   64 GiB    3.6880000000   USD
General purpose   m4.16xlarge      64   256 GiB   14.7520000000  USD
General purpose   m5.large         2    8 GiB     0.6960000000   USD
(省略)
General purpose   m6i.metal        128  512 GiB   29.1840000000  USD
General purpose   t3.xlarge        4    16 GiB    0.7712000000   USD
General purpose   t3.2xlarge       8    32 GiB    1.5424000000   USD
Memory optimized  r4.large         2    15.25 GiB 0.7320000000   USD
Memory optimized  r4.xlarge        4    30.5 GiB  0.9840000000   USD
Memory optimized  r4.2xlarge       8    61 GiB    1.9680000000   USD
Memory optimized  r4.4xlarge       16   122 GiB   3.9360000000   USD
Memory optimized  r4.8xlarge       32   244 GiB   7.8720000000   USD
Memory optimized  r4.16xlarge      64   488 GiB   15.7440000000  USD
Memory optimized  r5.large         2    16 GiB    0.7240000000   USD
(省略)
Memory optimized  x2iedn.metal     128  4096 GiB  59.9320000000  USD
Storage optimized i3.large         2    15.25 GiB 0.7550000000   USD
Storage optimized i3.xlarge        4    30.5 GiB  1.0300000000   USD
Storage optimized i3.2xlarge       8    61 GiB    2.0600000000   USD
Storage optimized i3.4xlarge       16   122 GiB   4.1200000000   USD
Storage optimized i3.8xlarge       32   244 GiB   8.2400000000   USD
Storage optimized i3.16xlarge      64   488 GiB   16.4800000000  USD
Storage optimized i3.metal         72   512 GiB   16.4800000000  USD
Storage optimized i3en.large       2    16 GiB    0.8380000000   USD
(省略)
Storage optimized i4i.metal        128  1024 GiB  34.1310000000  USD

SavingsPlans

以下の料金表データを取得します。

aws.amazon.com

1. 料金表データファイルのバージョン取得

オンデマンド・リザーブドインスタンスと同じく、SavingsPlansの料金表データファイルも以下の分類で管理されています。

  • リージョン
  • サービス
  • バージョン

SavingsPlansでは料金表データファイルダウンロード時に「current」を指定できません。
そのため、料金表データファイルを取得する前に、取得対象のバージョンを確認する必要があります。

SavingsPlansの料金表データファイルのバージョン一覧は以下のURLからダウンロードできます。

https://pricing.us-east-1.amazonaws.com/savingsPlan/v1.0/aws/savingsPlanCode/current/index.json
  ※savingsPlanCodeには、「AWSComputeSavingsPlan」または「AWSMachineLearningSavingsPlans」を指定

※オンデマンド・リザーブドインスタンスのバージョンとSavingsPlansのバージョンは異なります。

以下URLから料金表データファイルのバージョン一覧をダウンロードします。

https://pricing.us-east-1.amazonaws.com/savingsPlan/v1.0/aws/AWSComputeSavingsPlan/current/index.json

ダウンロードしたファイルは以下の構成になっていました。

PS C:\Users\user\Downloads> gc .\index.json
{
  "disclaimer" : "This pricing list is for informational purposes only. All prices are subject to the additional terms included in the pricing pages on http://aws.amazon.com. All Free Tier prices are also subject to the terms included at https://aws.amazon.com/free/",
  "publicationDate" : "2025-04-29T21:50:59Z",
  "currentOfferVersionUrl" : "/savingsPlan/v1.0/aws/AWSComputeSavingsPlan/current/region_index.json",
  "versions" : [ {
    "publicationDate" : "2025-04-29T21:50:59Z",
    "offerVersionUrl" : "/savingsPlan/v1.0/aws/AWSComputeSavingsPlan/20250429215059/region_index.json"
  }, {
    "publicationDate" : "2025-04-26T00:06:25Z",
    "offerVersionUrl" : "/savingsPlan/v1.0/aws/AWSComputeSavingsPlan/20250426000625/region_index.json"
  }, {
(省略)
  }, {
    "publicationDate" : "2019-11-06T16:15:48Z",
    "offerVersionUrl" : "/savingsPlan/v1.0/aws/AWSComputeSavingsPlan/20191106161548/region_index.json"
  } ],
  "formatVersion" : "v1.0"
}

大阪リージョンの料金表データファイルの最新バージョンは「20250429215059」であることが確認できました。

2. 料金表データファイル取得

料金表データファイルは以下のURLからダウンロードできます。

https://pricing.us-east-1.amazonaws.com/savingsPlan/v1.0/aws/savingsPlanCode/version/regionCode/index.format
  ※各項目には以下の値を設定します。
      savingsPlanCode:「AWSComputeSavingsPlan」または「AWSMachineLearningSavingsPlans」を指定
      version:取得する料金表データのバージョン ※「current」は指定不可
      regionCode:取得対象のリージョンコード
      format:取得するファイルの拡張子  ※「json」または「csv」を指定

以下URLにアクセスし、最新バージョンの料金表データファイルをダウンロードします。

https://pricing.us-east-1.amazonaws.com/savingsPlan/v1.0/aws/AWSComputeSavingsPlan/20250429215059/ap-northeast-3/index.csv

3. 料金表データ取得

料金表データファイルは、次のような構成となっていました。

PS C:\Users\user\Downloads> gc .\index.csv
FormatVersion,v1.0
Disclaimer,This pricing list is for informational purposes only. All prices are subject to the additional terms included in the pricing pages on http://aws.amazon.com. All Free Tier prices are also subject to the terms included at https://aws.amazon.com/free/
Publication Date,2025-04-29T21:50:59Z
Version,20250429215059
OfferCode,AmazonComputeSavingsPlan
SKU,RateCode,Unit,EffectiveDate,DiscountedRate,(省略)
K2NUE6GADK6AFT9C,K2NUE6GADK6AFT9C.252XMDTMHWRFAAZZ,Hrs,2025-02-13T07:50:30Z,0.2768,(省略)
(以下、料金表データが続く)

※1~5行目に料金表データファイルの情報、6行目に項目名、7行目以降に料金表データが記載されている

また、ファイル内の項目は以下となっていました。

PS C:\Users\user\Downloads> $csv = gc '.\index.csv' | select -Skip 5 | ConvertFrom-Csv
PS C:\Users\user\Downloads> echo $csv | gm | ?{$_.MemberType -ne 'Method' } | fw -Property Name -Column 4


Currency                      Description                   DiscountedInstanceType        DiscountedOperation
DiscountedRate                DiscountedRegionCode          DiscountedServiceCode         DiscountedSKU
DiscountedUsageType           EffectiveDate                 Granularity                   Instance Family
LeaseContractLength           LeaseContractLengthUnit       Location                      Location Type
Operation                     Product Family                PurchaseOption                RateCode
ServiceCode                   SKU                           Unit                          UsageType

料金表データファイルからSavingsPlansの料金を取得します。

PS C:\Users\user\Downloads> echo $csv |
>> ?{
>>     $_.DiscountedServiceCode -eq 'AmazonEC2' -and
>>     $_.'Product Family' -eq 'ComputeSavingsPlans' -and
>>     $_.LeaseContractLength -eq '1' -and
>>     $_.LeaseContractLengthUnit -eq 'year' -and
>>     $_.PurchaseOption -eq 'No Upfront' -and
>>     $_.DiscountedOperation -eq 'RunInstances:0010' -and
>>     $_.DiscountedInstanceType -eq 'c5.2xlarge' -and
>>     $_.DiscountedUsageType -Match 'BoxUsage'
>> } |
>> select DiscountedRate, Currency

DiscountedRate Currency
-------------- --------
0.468          USD

※料金表データファイルには、オペレーティングシステムとテナンシーの項目が無いため、使用オペレーションと使用タイプから抽出します。

docs.aws.amazon.com

料金表ページと同じ金額が取得できました!

まとめ

今回はAWS Price List Bulk APIを使用して料金表データを取得しました。

AWS Price List Bulk APIでは料金表データを一括してダウンロードできるので、計算で使用するための元データとして料金表データを取得する場合に便利です。また、過去の料金表データを取得できるので、1年前など特定時期の料金表を参照したい場合にも活用できます。

一方、料金表データファイルの取得や取得後の情報抽出など複数の作業が必要となるため、最新の料金表データを参照したいだけであればAWS Price List Query APIや料金表ページから参照したほうがよさそうです。

お知らせ

APCはAWS Advanced Tier Services (アドバンストティアサービスパートナー) 認定を受けております。

その中で私達クラウド事業部はAWSなどのクラウド技術を活用したSI/SESのご支援をしております。

www.ap-com.co.jp

また、一緒に働いていただける仲間も募集中です!
今年もまだまだ組織規模拡大中なので、ご興味持っていただけましたらぜひお声がけください。

www.ap-com.co.jp