Skip to content

Instantly share code, notes, and snippets.

@king-panda
Last active August 29, 2015 14:20
Show Gist options
  • Save king-panda/ad0bc7c3c1eb0a5de908 to your computer and use it in GitHub Desktop.
Save king-panda/ad0bc7c3c1eb0a5de908 to your computer and use it in GitHub Desktop.
【Unity】AWSの利用料金をaws cliから取得して、Unity(WebGL)で可視化した ref: http://qiita.com/kingpanda/items/346c96cb70d7dc6c3061
{
"Timestamp": "2015-05-11T01:07:00Z",
"Maximum": 0.13,
"Unit": "None"
}
#!/bin/bash
aws cloudwatch --region us-east-1 get-metric-statistics \
--namespace "AWS/Billing" \
--metric-name "EstimatedCharges" \
--dimensions "[{\"Value\":\"AmazonEC2\",\"Name\":\"ServiceName\"},{\"Value\":\"USD\",\"Name\":\"Currency\"}]" \
--period 60 \
--start-time `date -u -d '3 hours ago' +%Y-%m-%dT%TZ` \
--end-time `date -u +%Y-%m-%dT%TZ` \
--statistics "Maximum" \
| jq '.Datapoints | sort_by(.Timestamp) | reverse | .[0]' > bill.json
cat bill.json
var coin : Transform;
function Start() {
}
//Webサイト側から呼び出される関数
function bill(count:Number) {
for (var i = 0; i < count; i++){
yield WaitForSeconds(1.0);
billing();
}
}
function billing (){
Instantiate(coin,transform.position,transform.rotation);
}
<center>
<p class="cpt">現在の利用料は、$*******です(※コイン一枚につき$0.01)</p>
<button class="btn">料金を見る</botton>
</center>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
s = document.querySelector("button");
s.addEventListener("click", function() {
// jsonの読み込み
$.getJSON("bill.json" , function(data) {
// キャプションの置き換え
document.querySelector(".cpt").innerHTML ="現在の利用料は、$"+data.Maximum+"です(※コイン一枚につき$0.01)";
// コインの単位の変換
var money = data.Maximum/0.01;
// WebGLへパラメタ送信
SendMessage("sample","bill",money);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment