AWS Price List APIがリージョン別価格を提供するようになりました

2017.05.03

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

2017/04/20 のサービスアップデートにより、サービスごとのプライスリストを提供する AWS Price List API がリージョン別のプライスリスト提供に対応しました

全リージョンでサービス展開しているわけではなく、東京リージョンなど、特定のリージョンで重点的にサービス展開しており、そのリージョンでのプライスリストが欲しいケースにおいて、プライスリストファイルのデータサイズが大幅に減ります。

例えば 10 リージョンに対応したサービスの場合、リージョン別ファイルを利用すると、取得するファイルサイズはほぼ 1/10 になります。

サービスアップデート前後での通知文の違い

プライスリストの変更は SNS を購読すると受け取れます

サービス変更前の本文

サービス別にプライスリストを受け取るSNS(arn:aws:sns:us-east-1:278350005181:price-list-api)を購読していた場合、従来は次のようなメッセージが配信されていました。サービスアップデート前は、次のようなメッセージが配信されていました。

Hello,

You have received this notification because you subscribed to receiving updates from SNS topic arn:aws:sns:us-east-1:278350005181:daily-aggregated-price-list-api

We've published a new version of the offer file for Service AmazonChime. Use the following URLs to download the file:
   - JSON Format : https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonChime/current/index.json
   - CSV Format : https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonChime/current/index.csv

To learn more about the file formats, see  http://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/price-changes.html.

Thank You,
Amazon Web Services Team

サービス変更後の本文

サービスアップデート後は、次のようなメッセージが配信されるようになりました。

Hello,

You have received this notification because you subscribed to receiving updates from SNS topic arn:aws:sns:us-east-1:278350005181:daily-aggregated-price-list-api

We've published a new version of the offer file for Service AmazonApiGateway. Use the following URLs to download the file:
   - JSON Format : https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonApiGateway/current/index.json
   - CSV Format : https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonApiGateway/current/index.csv
   - Region Index Url : https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonApiGateway/current/region_index.json

To learn more about the file formats, see  http://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/price-changes.html.

Thank You,
Amazon Web Services Team
  • JSON Format
  • CSV Format

に追加して

  • Region Index Url

も含まれるようになっています。

このインデックスファイルをもとに、実際にリージョン別プライスリストデータを取得してみます。

URL の違い

List Price API で提供されている URL の違いをまとめたのが以下です

全リージョン分プライスリストデータ

https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/{AWS Service Name}/current/index.json

例) https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonS3/current/index.json

リージョン別のインデックスデータ

https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/{AWS Service Name}/current/region_index.json

例) https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonS3/current/region_index.json

リージョン別プライスリストデータ

https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/{AWS Service Name}/{Specific Date}/{Region}/region_index.json

例) https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonS3/20170424230114/ap-northeast-1/index.json

リージョン別プライスリストを取得する

それでは、今回追加された Region Index Url を利用して、特定のリージョンのプライスリストを取得しましょう。

リージョン別インデックスファイルの取得

プライスリスト変更通知文の Region Index Url のURLを GET すると、リージョン別プライスリストのインデックスファイルを取得できます。

$ curl -o s3_region_index.json https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonS3/current/region_index.json

実際に取得したファイルは以下です。

s3_region_index.json

{
  "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/",
  "publicationDate" : "2017-04-24T23:01:14Z",
  "regions" : {
    "ap-south-1" : {
      "regionCode" : "ap-south-1",
      "currentVersionUrl" : "/offers/v1.0/aws/AmazonS3/20170424230114/ap-south-1/index.json"
    },
    "eu-west-2" : {
      "regionCode" : "eu-west-2",
      "currentVersionUrl" : "/offers/v1.0/aws/AmazonS3/20170424230114/eu-west-2/index.json"
    },
    "eu-west-1" : {
      "regionCode" : "eu-west-1",
      "currentVersionUrl" : "/offers/v1.0/aws/AmazonS3/20170424230114/eu-west-1/index.json"
    },
    "ap-northeast-2" : {
      "regionCode" : "ap-northeast-2",
      "currentVersionUrl" : "/offers/v1.0/aws/AmazonS3/20170424230114/ap-northeast-2/index.json"
    },
    "ap-northeast-1" : {
      "regionCode" : "ap-northeast-1",
      "currentVersionUrl" : "/offers/v1.0/aws/AmazonS3/20170424230114/ap-northeast-1/index.json"
    },
    "sa-east-1" : {
      "regionCode" : "sa-east-1",
      "currentVersionUrl" : "/offers/v1.0/aws/AmazonS3/20170424230114/sa-east-1/index.json"
    },
    "ca-central-1" : {
      "regionCode" : "ca-central-1",
      "currentVersionUrl" : "/offers/v1.0/aws/AmazonS3/20170424230114/ca-central-1/index.json"
    },
    "us-gov-west-1" : {
      "regionCode" : "us-gov-west-1",
      "currentVersionUrl" : "/offers/v1.0/aws/AmazonS3/20170424230114/us-gov-west-1/index.json"
    },
    "ap-southeast-1" : {
      "regionCode" : "ap-southeast-1",
      "currentVersionUrl" : "/offers/v1.0/aws/AmazonS3/20170424230114/ap-southeast-1/index.json"
    },
    "ap-southeast-2" : {
      "regionCode" : "ap-southeast-2",
      "currentVersionUrl" : "/offers/v1.0/aws/AmazonS3/20170424230114/ap-southeast-2/index.json"
    },
    "eu-central-1" : {
      "regionCode" : "eu-central-1",
      "currentVersionUrl" : "/offers/v1.0/aws/AmazonS3/20170424230114/eu-central-1/index.json"
    },
    "us-east-1" : {
      "regionCode" : "us-east-1",
      "currentVersionUrl" : "/offers/v1.0/aws/AmazonS3/20170424230114/us-east-1/index.json"
    },
    "us-east-2" : {
      "regionCode" : "us-east-2",
      "currentVersionUrl" : "/offers/v1.0/aws/AmazonS3/20170424230114/us-east-2/index.json"
    },
    "us-west-1" : {
      "regionCode" : "us-west-1",
      "currentVersionUrl" : "/offers/v1.0/aws/AmazonS3/20170424230114/us-west-1/index.json"
    },
    "us-west-2" : {
      "regionCode" : "us-west-2",
      "currentVersionUrl" : "/offers/v1.0/aws/AmazonS3/20170424230114/us-west-2/index.json"
    }
  }
}

リージョン別に currentVersionUrl が定義されたインデックスデータが並んでいます。

リージョン別プライスリストファイルの取得

先程と同じホスト名(pricing.us-east-1.amazonaws.com)を利用し、パス部分に、プライスリストデータが欲しいリージョンの currentVersionUrl を指定して GET すると、リージョン別プライスリストデータを取得できます。

$ curl -o s3_tokyo.json https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonS3/20170424230114/ap-northeast-1/index.json

実際に取得したファイルは以下です。

s3_tokyo.json

{
  "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/",
  "offerCode" : "AmazonS3",
  "version" : "20170424230114",
  "publicationDate" : "2017-04-24T23:01:14Z",
  "products" : {
    "YTBTUFDC7FRAJJAP" : {
      "sku" : "YTBTUFDC7FRAJJAP",
      "productFamily" : "Data Transfer",
      "attributes" : {
        "servicecode" : "AWSDataTransfer",
        "transferType" : "Accelerated InterRegion Outbound using edge locations within US, Europe or Japan",
        "fromLocation" : "EU (Ireland)",
        "fromLocationType" : "AWS Region",
        "toLocation" : "South America (Sao Paulo)",
        "toLocationType" : "AWS Region",
        "usagetype" : "EU-SAE1-AWS-Out-ABytes-T1",
        "operation" : ""
      }
    },
    ...

リージョン別プライスリストデータをもう少し細かく確認

先程取得した S3 のリージョン別プライスリストを例に、実際のデータをもう少し詳細に追って、リージョン別データであることを確認します。

productFamily は以下の4種類が存在します。

  • API Request
  • Data Transfer
  • Fee
  • Storage

順に確認します。

API Request

"productFamily" : "API Request" は以下のようなデータ構造をしています。

"DUCV6P6RVNW3CNWJ" : {
  "sku" : "DUCV6P6RVNW3CNWJ",
  "productFamily" : "API Request",
  "attributes" : {
    "servicecode" : "AmazonS3",
    "location" : "Asia Pacific (Tokyo)",
    "locationType" : "AWS Region",
    "group" : "S3-API-SIA-Retrieval",
    "groupDescription" : "Object Retrieval in Standard-Infrequent Access",
    "usagetype" : "APN1-Retrieval-SIA",
    "operation" : ""
  }

location が対象リージョンです。

Data Transfer

"productFamily" : "Data Transfer" は以下のようなデータ構造をしています。

"PYGPVTGGW5GRFAPU" : {
  "sku" : "PYGPVTGGW5GRFAPU",
  "productFamily" : "Data Transfer",
  "attributes" : {
    "servicecode" : "AWSDataTransfer",
    "transferType" : "Accelerated InterRegion Outbound using edge locations outside US, Europe or Japan",
    "fromLocation" : "Asia Pacific (Tokyo)",
    "fromLocationType" : "AWS Region",
    "toLocation" : "US East (N. Virginia)",
    "toLocationType" : "AWS Region",
    "usagetype" : "APN1-USE1-AWS-Out-ABytes-T2",
    "operation" : ""
  }
},

Data Transfer であれば、

  • fromLocation
  • toLocation

のどちらかが対象リージョンです。

Fee

"productFamily" : "Fee" は以下のようなデータ構造をしています。

"XVWPJG9SMSSHZ9HQ" : {
  "sku" : "XVWPJG9SMSSHZ9HQ",
  "productFamily" : "Fee",
  "attributes" : {
    "servicecode" : "AmazonS3",
    "location" : "Asia Pacific (Tokyo)",
    "locationType" : "AWS Region",
    "feeCode" : "S3-Expedited-Retrieval",
    "feeDescription" : "Fee for Expedited Retrieval of data stored",
    "usagetype" : "APN1-Expedited-Retrieval-Bytes",
    "operation" : ""
  }
},

location が対象リージョンです。

Storage

"productFamily" : "Storage" は以下のようなデータ構造をしています。

"VYPMFZ3C34HQCUWR" : {
  "sku" : "VYPMFZ3C34HQCUWR",
  "productFamily" : "Storage",
  "attributes" : {
    "servicecode" : "AmazonS3",
    "location" : "Asia Pacific (Tokyo)",
    "locationType" : "AWS Region",
    "availability" : "N/A",
    "storageClass" : "Archive",
    "volumeType" : "Amazon Glacier",
    "usagetype" : "APN1-TimedStorage-GlacierByteHrs",
    "operation" : "",
    "durability" : "99.999999999%"
  }
},

location が対象リージョンです。

ファイルフォーマットについて

従来のリストプライスは

  • JSON
  • CSV

の2形式に対応していました。

リージョン別ファイルの JSON/CSV 対応状況を確認します。

インデックスファイルについて

インデックスファイルURLの最後の拡張子部分を csv に変更してCSV形式のインデックスファイルを要求すると、次のように 403 Forbidden エラーがかえってきました。

$ curl https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonS3/current/region_index.csv
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>8B1E91CB351C6280</RequestId><HostId>ldzLVYmGNDlV1ffWatLRV/VYE6Oo74/uJ+mCCjxfNCZHWcaIJaePkYGA0MIY/SEBL+7dOwR+/R4=</HostId></Error>

残念ながらリージョン別インデックスファイルは JSON のみに対応しているようです。

リージョン別プライスリストデータファイルについて

JSON型のリージョン別インデックスファイルから参照されるリージョン別プライスリストデータのURL(currentVersionUrl)もJSON形式のものとなっています。

このURLの最後の拡張子部分を csv に変更すると、次のように CSV 形式のデータを取得できました。

$ curl https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonS3/20170424230114/ap-northeast-1/index.csv
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0"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","2017-04-24T23:01:14Z"
"Version","20170424230114"
"OfferCode","AmazonS3"
"SKU","OfferTermCode","RateCode","TermType","PriceDescription","EffectiveDate","StartingRange","EndingRange","Unit","PricePerUnit","Currency","Product Family","serviceCode","Location","Location Type","Availability","Storage Class","Volume Type","Fee Code","Fee Description","Group","Group Description","Transfer Type","From Location","From Location Type","To Location","To Location Type","usageType","operation","Durability"
"JDTB869VVEH9D6S6","JRTCKXETXF","JDTB869VVEH9D6S6.JRTCKXETXF.6YS6EN2CT7","OnDemand","$0.040 per GB - Asia Pacific (Tokyo) Amazon S3 accelerated data transfer to Asia Pacific (Mumbai)","2017-04-01","0","Inf","GB","0.0400000000","USD","Data Transfer","AWSDataTransfer","","","","","","","","","","Accelerated InterRegion Outbound from close by location","Asia Pacific (Tokyo)","AWS Region","Asia Pacific (Mumbai)","AWS Region","APN1-APS3-AWS-Out-ABytes","",""
"9T23NTZE42HNQSMG","JRTCKXETXF","9T23NTZE42HNQSMG.JRTCKXETXF.6YS6EN2CT7","OnDemand","$0.040 per GB - South America (Sao Paulo) Amazon S3 accelerated data transfer from Asia Pacific (Tokyo)","2017-04-01","0","Inf","GB","0.0400000000","USD","Data Transfer","AWSDataTransfer","","","","","","","","","","Accelerated InterRegion Inbound using edge locations within US, Europe or Japan","South America (Sao Paulo)","AWS Region","Asia Pacific (Tokyo)","AWS Region","SAE1-APN1-AWS-In-ABytes-T1","",""
"PKC9TNBVZA4G6BZ5","JRTCKXETXF","PKC9TNBVZA4G6BZ5.JRTCKXETXF.6YS6EN2CT7","OnDemand","$0.09 per GB - Asia Pacific (Tokyo) data transfer to EU (London)","2017-04-01","0","Inf","GB","0.0900000000","USD","Data Transfer","AWSDataTransfer","","","","","","","","","","InterRegion Outbound","Asia Pacific (Tokyo)","AWS Region","EU (London)","AWS Region","APN1-EUW2-AWS-Out-Bytes","",""
"R9DT92BCYWWH9KQW","JRTCKXETXF","R9DT92BCYWWH9KQW.JRTCKXETXF.6YNURZBX9Y","OnDemand","$0.0264 per GB - first 1 TB / month of storage used - Reduced Redundancy Storage","2017-04-01","0","1024","GB-Mo","0.0264000000","USD","Storage","AmazonS3","Asia Pacific (Tokyo)","AWS Region","99.99%","Non-Critical Data","Reduced Redundancy","","","","","","","","","","APN1-TimedStorage-RRS-ByteHrs","","99.99%"
...

CSVのリストプライスデータを利用してきた場合は、リージョン別インデックスデータファイルのURLを一部加工してCSVデータを要求するのが良いかと思います。

リージョン別プライスリストデータを current で要求

従来の全リージョン分のプライスリストデータやリージョン別プライスリストインデックスは current で要求するのに対して

  • https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonS3/current/index.json
  • https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonS3/current/region_index.json

リージョン別プライスリストデータは年月日指定しています。

  • https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonS3/20170424230114/ap-northeast-1/index.json

現時点の動作としては current と 指定する年月日が同じものを指している場合、この2つは置き換え可能なようです。

例えば current が 20170424230114 を指している場合、

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

のかわりに

https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonS3/20170424230114/index.json

としたり、

https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonS3/20170424230114/ap-northeast-1/index.json

のかわりに

https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonS3/current/ap-northeast-1/index.json

としても同じデータを取得できました。

(サービス, タイムスタンプ) を何処かに残しておくと、やんごとなき理由により過去のある時点のプライスリストが欲しくなったときに、救世主となるかもしれません。

まとめ

本日は、日本国内ではごく少数しか活用していないと思われる、プライスリスト API のリージョン別提供対応を紹介しました。

どこかの誰かのお役に立てば嬉しいです。

参照