LoginSignup
5
1

More than 3 years have passed since last update.

Lambda から Google API を呼ぶと権限ファイルの書き込みで `[Errno 30] Read-only file system` になる

Last updated at Posted at 2019-05-06

背景

  • 以下の記事に沿って Gmail API を叩く Python スクリプトを作成
  • スクリプトを Lambda で動くようにして、実行したところ [Errno 30] Read-only file system が発生
    • ローカルで実行したときには起きなかった

原因

  • 権限ファイル (client_id.json) の書き込みでエラーになっている模様
  • エラーのスタックトレースを見ると、oauth2client ライブラリ内で発生しているようだった
"errorMessage": "[Errno 30] Read-only file system: 'client_id.json'",
  :
    [
      "/var/task/oauth2client/file.py",
      79,
      "locked_put",
      "f = open(self._filename, 'w')"
    ],
  :
  • self._filename は Storage クラスのコンストラクタ引数
  • Lambda が書き込みできるのは /tmp 配下のファイルのみなので、Read-only エラーとなった

対応

  • client_id.json を一旦 /tmp に退避させてから Storage クラスを作成する
before
    user_secret_file = 'client_id.json'
    store = Storage(user_secret_file)
    credentials = store.get()
after
import shutil
 :
    user_secret_file = 'client_id.json'
    user_secret_tmp_path = '/tmp/' + user_secret_file
    shutil.copy2(user_secret_file, user_secret_tmp_path)

    store = Storage(user_secret_tmp_path)
    credentials = store.get()

参考

5
1
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
5
1