かれ4

かれこれ4個目のブログ

AWS の課金情報(Account Activity)をAPIじゃないけど、スクレイピングで取得するやつ作ってみた Java のソース付き

#AWS77で多い 課金情報取得のAPIが欲しいというのがあって、
自分も欲しいと思ってた。
ソースコードと、コマンドラインツールと、jarファイルをひとまとめにしたものはこちら

google codeはこちら
http://code.google.com/p/aws-account-activity/downloads/list

AWS SDK for JavaApache 2.0 licenseらしいので
これのLicenseもApache2.0 で

ライブラリは
AWSSDKforJavaが必要です。
あとそれに付いてる3rdpartyなライブラリ達(多分HTTPClientしか使ってない)

使い方

Javaから使う
 ActivityClient ac = 
 new ActivityClient(
   new MailPassAWSCredentials(mailaddress, password));
 Activity activity = ac.get();
 for (ActivityItem item : activity) {
   item.getServie(); // サービス名 AmazonEC2とか
   item.getRegion(); // United States Europe Asia Pacific (Tokyo) Regionとか
   item.getRange(); // どの単価かみたいなやつ
   item.getCommodity(); // どんな従量か
   item.getPrice();  // 値段(どる)
  // これ以外の機能も付いてるけど、うまく行ったり行かなかったりするので、ココには書きません。
 }
 
簡易版コマンドラインツール

bin/account-activity.sh

$ bin/account-activity.sh メールアドレス パスワード [フィルタ]
  
出力>
AmazonCloudFront	United States		$0.150 per GB - first 10 TB / month data transfer out	0.421 GB	0.06
AmazonCloudFront	United States		$0.0075 per 10,000 HTTP Requests	361 Requests	0.01
AmazonCloudFront	Europe		$0.150 per GB - first 10 TB / month data transfer out	0.009 GB	0.01
AmazonCloudFront	Europe		$0.0090 per 10,000 HTTP Requests	115 Requests	0.01
AmazonCloudFront	Asia Pacific (Tokyo) Region		$0.201 per GB - first 10 TB / month data transfer out  (includes consumption tax).	0.318 GB	0.06
AmazonCloudFront	Asia Pacific (Tokyo) Region		$0.0095 per 10,000 HTTP Requests (includes consumption tax).	456 Requests	0.01
AmazonCloudFront	Asia Pacific (Singapore) Region		$0.190 per GB - first 10 TB / month data transfer out	0.092 GB	0.02
AmazonCloudFront	Asia Pacific (Singapore) Region		$0.0090 per 10,000 HTTP Requests	124 Requests	0.01
AmazonEC2	US East (Northern Virginia) Region		$0.02 per Micro Instance (t1.micro) instance-hour (or partial hour)	451 Hrs	9.01
AmazonEC2	US East (Northern Virginia) Region		$0.10 per GB-month of provisioned storage	35.679 GB-Mo	3.56
AmazonEC2	US East (Northern Virginia) Region		$0.10 per 1 million I/O requests	1,961,776 IOs	0.20
AmazonEC2	US East (Northern Virginia) Region		$0.15 per GB-Month of snapshot data stored	0.371 GB-Mo	0.06
AmazonEC2	Asia Pacific (Tokyo) Region		$0.011 per Micro Instance (t1.micro) instance-hour (or partial hour)	451 Hrs	4.96
AmazonEC2	Asia Pacific (Tokyo) Region		$0.10 per Small Instance (m1.small) instance-hour (or partial hour)	450 Hrs	45.00
AmazonEC2	Asia Pacific (Tokyo) Region		$0.027 per Micro Instance (t1.micro) instance-hour (or partial hour)	424 Hrs	11.44
AmazonEC2	Asia Pacific (Tokyo) Region		$0.80 per High-CPU Extra Large Instance (c1.xlarge) instance-hour (or partial hour)	3 Hrs	2.39
AmazonEC2	Asia Pacific (Tokyo) Region		$0.01 per non-attached Elastic IP address per complete hour	376 Hrs	3.75
AmazonEC2	Asia Pacific (Tokyo) Region		$0.12 per GB-month of provisioned storage	42.938 GB-Mo	5.15
AmazonEC2	Asia Pacific (Tokyo) Region		$0.12 per 1 million I/O requests	1,425,965 IOs	0.17
AmazonEC2	Asia Pacific (Tokyo) Region		$0.16 per GB-Month of snapshot data stored	2.302 GB-Mo	0.37
AmazonEC2	Asia Pacific (Tokyo) Region		$0.011 per 1,000 puts (when saving a snapshot)	88 Requests	0.01
AmazonEC2	Asia Pacific (Tokyo) Region		$0.008 per GB Data Processed by the LoadBalancer	0.486 GB	0.01
AmazonEC2	Asia Pacific (Tokyo) Region		$0.028 per LoadBalancer-hour (or partial hour)	377 Hrs	10.56
AmazonSimpleDB	US East (Northern Virginia) Region		$0.00 per Compute-Hour consumed first 25 hours per month	2.788 Hrs	0.00
AmazonSimpleDB	US East (Northern Virginia) Region		$0.00 per GB-Month of storage for first 1 GB-Month	0.012 GB-Mo	0.00
AmazonSimpleDB	Asia Pacific (Tokyo) Region		$0.00 per Compute-Hour consumed first 25 hours per month	25 Hrs	0.00
AmazonSimpleDB	Asia Pacific (Tokyo) Region		$0.162 per Compute-Hour consumed beyond first 25 free hours per month	120.625 Hrs	19.53
AmazonSimpleDB	Asia Pacific (Tokyo) Region		$0.00 per GB-Month of storage for first 1 GB-Month	0.019 GB-Mo	0.00
AmazonSES			Cost per recipient of SendEmail or SendRawEmail invoked from EC2 (free)	5,831 Count	0.00
AmazonS3	US Standard Region		$0.140 per GB - first 1 TB / month of storage used	100.102 GB-Mo	14.00
AmazonS3	US Standard Region		$0.01 per 1,000 PUT, COPY, POST, or LIST requests	156,033 Requests	1.56
AmazonS3	US Standard Region		$0.01 per 10,000 GET and all other requests	690,848 Requests	0.69
AmazonS3	Asia Pacific (Tokyo) Region		$0.150 per GB - first 1 TB / month of storage used	31.114 GB-Mo	4.67
AmazonS3	Asia Pacific (Tokyo) Region		$0.01 per 1,000 PUT, COPY, POST, or LIST requests	9 Requests	0.01
AmazonS3	Asia Pacific (Tokyo) Region		$0.01 per 10,000 GET and all other requests	15 Requests	0.01
AWSDataTransfer	US East (Northern Virginia) and US Standard Regions		$0.100 per GB - data transfer in per month	42.081 GB	4.20
AWSDataTransfer	US East (Northern Virginia) and US Standard Regions		$0.000 per GB - first 1 GB of data transferred out per month	1.000 GB	0.00
AWSDataTransfer	US East (Northern Virginia) and US Standard Regions		$0.150 per GB - up to 10 TB / month data transfer out	7.044 GB	1.06
AWSDataTransfer	US East (Northern Virginia) and US Standard Regions		$0.010 per GB - regional data transfer - in/out/between EC2 Avail Zones or when using public/elastic IP addresses or ELB	0.002 GB	0.01
AWSDataTransfer	Asia Pacific (Tokyo) Region		$0.100 per GB - data transfer in per month	4.031 GB	0.40
AWSDataTransfer	Asia Pacific (Tokyo) Region		$0.000 per GB - first 1 GB of data transferred out per month	0.517 GB	0.00
AWSDataTransfer	Asia Pacific (Tokyo) Region		$0.010 per GB - regional data transfer - in/out/between EC2 Avail Zones or when using public/elastic IP addresses or ELB	0.597 GB	0.01

おまけ

zipの中身

$ find ./ 
  bin
  # コマンドラインツールみたいなもの、サンプル的な昨日しか付いてない
  bin/account-activity.sh  
  # Javaのソースファイルから.jarまで
  build.sh
  #
  .//lib
  # 今回作った課金情報取得のやつ
  .//lib/aws-account-activity-0.0.1.jar
  # 以下 AWS sdk for javaからコピーしてきたもの達
  .//lib/aws-java-sdk-1.2.1.jar
  .//lib/third-party
  .//lib/third-party/commons-codec-1.3
  .//lib/third-party/commons-codec-1.3/commons-codec-1.3.jar
  .//lib/third-party/commons-codec-1.3/LICENSE.txt
  .//lib/third-party/commons-logging-1.1.1
  .//lib/third-party/commons-logging-1.1.1/commons-logging-1.1.1.jar
  .//lib/third-party/commons-logging-1.1.1/LICENSE.txt
  .//lib/third-party/commons-logging-1.1.1/NOTICE.txt
  .//lib/third-party/httpcomponents-client-4.1.1
  .//lib/third-party/httpcomponents-client-4.1.1/httpclient-4.1.1.jar
  .//lib/third-party/httpcomponents-client-4.1.1/httpcore-4.1.jar
  .//lib/third-party/httpcomponents-client-4.1.1/LICENSE.txt
  .//lib/third-party/httpcomponents-client-4.1.1/NOTICE.txt
  .//lib/third-party/jackson-1.4
  .//lib/third-party/jackson-1.4/jackson-core-asl-1.4.3.jar
  .//lib/third-party/jackson-1.4/LICENSE.txt
  .//lib/third-party/java-mail-1.4.3
  .//lib/third-party/java-mail-1.4.3/LICENSE.txt
  .//lib/third-party/java-mail-1.4.3/mail-1.4.3.jar
  .//lib/third-party/stax-api-1.0.1
  .//lib/third-party/stax-api-1.0.1/LICENSE.txt
  .//lib/third-party/stax-api-1.0.1/stax-api-1.0.1.jar
  .//lib/third-party/stax-ri-1.2.0
  .//lib/third-party/stax-ri-1.2.0/LICENSE.txt
  .//lib/third-party/stax-ri-1.2.0/stax-1.2.0.jar
  # javaのソースコード
  .//src
  .//src/jp
  .//src/jp/jawsug
  .//src/jp/jawsug/account
  .//src/jp/jawsug/account/Activity.java
  .//src/jp/jawsug/account/ActivityClient.java
  .//src/jp/jawsug/account/ActivityItem.java
  .//src/jp/jawsug/account/MailPassAWSCredentials.java