gspread

因為想操作 google 試算表,找到 gspread 這個專案。

官方網頁的設定方式語焉不詳:https://gspread.readthedocs.io/en/latest/oauth2.html

所以我設定方式後來是參考這篇:https://sites.google.com/site/zsgititit/home/python-cheng-shi-she-ji/shi-yongpython-shang-chuan-zi-liao-daogoogle-shi-suan-biao

Google API console 那邊會比較讓人搞不清楚怎麼弄,大致紀錄一下:

  1. 建立 service account,角色選「編輯者」
  2. 建立金鑰 (選 JSON),然後下載
  3. 要編輯的 google spreadsheet 那邊要設定「共用」,email 填 json 檔案裡的 client email

操作 google 試算表的方式可以參考官方文件:https://gspread.readthedocs.io/en/latest/user-guide.html#getting-a-cell-value

其他參考文章:

boto3 create_instances/run_instances

create_instances 是 boto3.resource(‘ec2’) 提供的,而 run_instances 是 boto3.client(‘ec2’) 提供的。

  • client(‘ec2’): A low-level client representing Amazon Elastic Compute Cloud (EC2)
  • resource(‘ec2’): A resource representing Amazon Elastic Compute Cloud (EC2)

主要不同點:Resources represent an object-oriented interface to Amazon Web Services (AWS). They provide a higher-level abstraction than the raw, low-level calls made by service clients. To use resources, you invoke the resource() method of a Session and pass in a service name。

也就是說實際上 ServiceResource 會去使用 client,簡單的說 ServiceResource 是一個 client wrapper (這可以從 boto3/session.py 看到)。

友情小提示:在閱讀程式碼時,用 function name 去找,會發現都找不到,實際上 boto3 library 會將 function call/parameters 轉換為 AWS API  呼叫送出去。