LoginSignup
2
3

More than 5 years have passed since last update.

Chromeのタブ開きすぎてパフォーマンスが辛いので積みタブ消化。

AWS Price List APIとは?

AWSサービスの価格を取ってくるAPIです。

結構最近リリースされた(はず)

とりあえず叩く

ルートのAPI

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

us-east-1となっているけども、他のリージョンに変えるとつながらないのでまだ対応していない様子。

戻り値

{
  "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": "2016-01-07T05:56:50Z",
  "offers": {
    "AmazonS3": {
      "offerCode": "AmazonS3",
      "versionIndexUrl": "/offers/v1.0/aws/AmazonS3/index.json",
      "currentVersionUrl": "/offers/v1.0/aws/AmazonS3/current/index.json"
    },
    "AmazonGlacier": {
      "offerCode": "AmazonGlacier",
      "versionIndexUrl": "/offers/v1.0/aws/AmazonGlacier/index.json",
      "currentVersionUrl": "/offers/v1.0/aws/AmazonGlacier/current/index.json"
    },
    "AmazonSES": {
      "offerCode": "AmazonSES",
      "currentVersionUrl": "/offers/v1.0/aws/AmazonSES/current/index.json"
    },
    "AmazonRDS": {
      "offerCode": "AmazonRDS",
      "currentVersionUrl": "/offers/v1.0/aws/AmazonRDS/current/index.json"
    },
    "AmazonSimpleDB": {
      "offerCode": "AmazonSimpleDB",
      "currentVersionUrl": "/offers/v1.0/aws/AmazonSimpleDB/current/index.json"
    },
    "AmazonDynamoDB": {
      "offerCode": "AmazonDynamoDB",
      "versionIndexUrl": "/offers/v1.0/aws/AmazonDynamoDB/index.json",
      "currentVersionUrl": "/offers/v1.0/aws/AmazonDynamoDB/current/index.json"
    },
    "AmazonEC2": {
      "offerCode": "AmazonEC2",
      "currentVersionUrl": "/offers/v1.0/aws/AmazonEC2/current/index.json"
    },
    "AmazonRoute53": {
      "offerCode": "AmazonRoute53",
      "currentVersionUrl": "/offers/v1.0/aws/AmazonRoute53/current/index.json"
    },
    "AmazonRedshift": {
      "offerCode": "AmazonRedshift",
      "versionIndexUrl": "/offers/v1.0/aws/AmazonRedshift/index.json",
      "currentVersionUrl": "/offers/v1.0/aws/AmazonRedshift/current/index.json"
    },
    "AmazonElastiCache": {
      "offerCode": "AmazonElastiCache",
      "versionIndexUrl": "/offers/v1.0/aws/AmazonElastiCache/index.json",
      "currentVersionUrl": "/offers/v1.0/aws/AmazonElastiCache/current/index.json"
    },
    "AmazonCloudFront": {
      "offerCode": "AmazonCloudFront",
      "currentVersionUrl": "/offers/v1.0/aws/AmazonCloudFront/current/index.json"
    },
    "awskms": {
      "offerCode": "awskms",
      "versionIndexUrl": "/offers/v1.0/aws/awskms/index.json",
      "currentVersionUrl": "/offers/v1.0/aws/awskms/current/index.json"
    },
    "AmazonVPC": {
      "offerCode": "AmazonVPC",
      "versionIndexUrl": "/offers/v1.0/aws/AmazonVPC/index.json",
      "currentVersionUrl": "/offers/v1.0/aws/AmazonVPC/current/index.json"
    }
  }
}

サービス別のプライスリストJSONのURLらしきものが並んでます。

とりあえず1つ叩いてみましょう。

EC2の価格を見る

そろそろ「まだEC2で消耗しているの?」と煽られそうな気配ですが気にせずAPIを叩きます。

先ほどの値からEC2の情報だけ見れるようにjqで絞り込みます。

$ curl https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/index.json | jq ".offers.AmazonEC2"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2721  100  2721    0     0  13938      0 --:--:-- --:--:-- --:--:-- 13953
{
  "offerCode": "AmazonEC2",
  "currentVersionUrl": "/offers/v1.0/aws/AmazonEC2/current/index.json"
}

/offers/v1.0/aws/AmazonEC2/current/index.jsonがそれっぽいですね。

ということでhttps://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.jsonで再度APIを叩いてみます。

% curl https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 39.9M  100 39.9M    0     0   995k      0  0:00:41  0:00:41 --:--:-- 1160k

40MBて・・・╭(°A°`)╮
EC2のインスタンスリストを全部返してきてるとかなのかもしれないです。

返ってくる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": "AmazonEC2",
  "version": "20151209144527",
  "publicationDate": "2015-12-09T14:45:27Z",
  "products": {
    "DQ578CGN99KG6ECF": {
      "sku": "DQ578CGN99KG6ECF",
      "productFamily": "Compute Instance",
      "attributes": {
        "servicecode": "AmazonEC2",
        "location": "US East (N. Virginia)",
        "locationType": "AWS Region",
        "instanceType": "hs1.8xlarge",
        "currentGeneration": "No",
        "instanceFamily": "Storage optimized",
        "vcpu": "17",
        "physicalProcessor": "Intel Xeon E5-2650",
        "clockSpeed": "2 GHz",
        "memory": "117 GiB",
        "storage": "24 x 2000",
        "networkPerformance": "10 Gigabit",
        "processorArchitecture": "64-bit",
        "tenancy": "Shared",
        "operatingSystem": "Windows",
        "licenseModel": "License Included",
        "usagetype": "BoxUsage:hs1.8xlarge",
        "operation": "RunInstances:0002",
        "preInstalledSw": "NA"
      }
    },
    "#以下省略" : "",
}

興味本位で行数を調べてみたところ 1,128,401行 ありました。
検索クエリ的なものは見当たらなかったので「とりあえずJSONでDLできるぜオラー」ってかんじなのかもです。

どう使う?

JavaScriptでどうこうするためというよりはElasticsearchとかHadoopとかぶん回しながら使う系かも。

ブラウザで40MBのJSONとかダウンロードしだしたら非常に辛いし。

追記

公式のドキュメントにこんなこと書かれてるので、マジで「とりあえずJSON見れるようにしたぜオラー」な気がしてきました。

To find a reserved Amazon EC2 instance using the JSON file
1:Download the JSON file.
2:Open the JSON file with your program of choice. For this example, we use Notepad++.
3:Press CRTL+F.
4:For Find what:, type reserved.
5:Choose Find All in Current Document.
From:http://docs.aws.amazon.com/ja_jp/awsaccountbilling/latest/aboutv2/procedures.html

「CRTL+Fで検索しろ」て・・・

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3