LoginSignup
13
12

More than 5 years have passed since last update.

boto + gspreadでAWSのデータをGoogleSpreadsheetに入れる

Last updated at Posted at 2014-06-08

botoでAWSのデータを取り、gspreadでGoogleDriveのspreadsheetに保存する。

環境

使用環境 バージョン
OSX 10.9.3
Python 2.7.6
boto 2.28.0
gspread 0.2.1

準備

Pythonモジュールboto,gspredをインストール

$ pip install boto gspread

gspread

Google Spreadsheetを操作する為のpythonモジュール
https://github.com/burnash/gspread
gspread API Reference
http://burnash.github.io/gspread/

boto

AWSの操作、情報取得等を行えるpythonモジュール
https://github.com/boto/boto
boto API Reference
http://boto.readthedocs.org/en/latest/ref/ec2.html

サンプルスクリプト

起動中のEC2インスタンスのインスタンスタイプから、
1時間、日、月毎の費用を1台ずつGoogleDriveのspreadsheetに記録するスクリプト
https://github.com/gacha-ru/scripts/tree/master/python/ec2_itype

※READMEにはスクリプトの使用方法しか書いてません。
 各モジュールについてはAPI Reference参照。
 書き方等、見辛かったりわかりにくい箇所がありましたらコメントいただけると幸いです。

※GoogleOAuthの変更(2015/5~)により、対象のシートに"client_email"のメールアドレス(account.jsonの"client_email")を
共有設定で「編集者」以上の権限で追加しておく必要があります。(2015/11/26 追記)

例:account.json
{
  "private_key_id": "tekitounaid",
  "private_key": "-----BEGIN PRIVATE KEY----- 〜略〜 \n-----END PRIVATE KEY-----\n",
  "client_email": "tekitou@developer.gserviceaccount.com",
  "client_id": "tekitou.apps.googleusercontent.com",
  "type": "service_account"
}

参考

Raspberry Pi で CPU 温度取得
http://u-tamax.jp/2013/09/raspberry-pi-%E3%81%A7-cpu-%E6%B8%A9%E5%BA%A6%E5%8F%96%E5%BE%97/

まとめ

GoogleDriveのspreadsheetをデータベースのように使うことで、可視化、共有を楽にできる。
「あのアカウントでどんなインスタンスを何台動かしてたっけ?」ということは多々あるので、
すぐに見れるようにするととても楽になる。

※Googleアカウントの管理とスプレッドシートの権限設定には十分注意する。

13
12
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
13
12