16

i have problem with googledrive credentials in AWS Lambda , after i deploy my .zip file before calling the function on the local machine , all is work , but after i deploy zip in AWS after ~30min i having lambda function error

  "errorMessage": "[Errno 30] Read-only file system: 'drive-python-quickstart.json'",
"errorType": "OSError",
  "stackTrace": [
    [
      "/var/task/lambda_function.py",
      33,
      "lambda_handler",
      "pageSize=10,fields=\"nextPageToken, files(id, name)\").execute()"
    ],
    [
      "/var/task/oauth2client/_helpers.py",
      133,
      "positional_wrapper",
      "return wrapped(*args, **kwargs)"
    ],
    [
      "/var/task/googleapiclient/http.py",
      835,
      "execute",
      "method=str(self.method), body=self.body, headers=self.headers)"
    ],
    [
      "/var/task/googleapiclient/http.py",
      162,
      "_retry_request",
      "resp, content = http.request(uri, method, *args, **kwargs)"
    ],
    [
      "/var/task/oauth2client/transport.py",
      186,
      "new_request",
      "credentials._refresh(orig_request_method)"
    ],
    [
      "/var/task/oauth2client/client.py",
      761,
      "_refresh",
      "self._do_refresh_request(http)"
    ],
    [
      "/var/task/oauth2client/client.py",
      802,
      "_do_refresh_request",
      "self.store.locked_put(self)"
    ],
    [
      "/var/task/oauth2client/file.py",
      79,
      "locked_put",
      "f = open(self._filename, 'w')"
    ]
  ]
}

in file file.py i have this code :

 def locked_put(self, credentials):
    """Write Credentials to file.
    Args:
        credentials: Credentials, the credentials to store.
    Raises:
        IOError if the file is a symbolic link.
    """
    self._create_file_if_needed()
    _helpers.validate_file(self._filename)
    f = open(self._filename, 'w')
    f.write(credentials.to_json())
    f.close()

def locked_delete(self):
    """Delete Credentials file.
    Args:
        credentials: Credentials, the credentials to store.
    """
    os.unlink(self._filename)

i try to set f = open(self._filename, 'w') set to 'r', but it doesn't help , maybe whom know how can i fix it ? Please suggest.

Андрей Ка
  • 756
  • 4
  • 14
  • 33

3 Answers3

41

Apparently you're trying to write a file where is not permitted. Lambda currently only supports writing files to the /tmp directory.

Tom Melo
  • 1,491
  • 1
  • 11
  • 17
  • 1
    could you please share how you fixed it! I'm facing this issue now - @Andrej – Geetha Ponnusamy Oct 31 '17 at 17:18
  • I just put all credents files on .zip ant set target to project dir. – Андрей Ка Oct 31 '17 at 17:43
  • I did the same, put all files inside .zip and uploaded in s3 and used that s3 link in lambda. In this case, I'm getting "errorType": "IOError", "errorMessage": "[Errno 30] Read-only file system: 'drive-python-quickstart.json'".. Any suggestion how to resolve this! Thanks in advance – Geetha Ponnusamy Nov 01 '17 at 03:36
  • how yo fixed it? I still get that error- [Errno 30] Read-only file system: '1587472029.zip' when I create a file in /tmp folder and tries to upload it to EC2? – Vikramsinh Gaikwad Apr 21 '20 at 12:30
  • If anyone is facing this, in your lambda function directory just create a folder `tmp` and then just change the file path that you want to write to, to `/tmp/FILE`. – yudhiesh May 03 '21 at 08:16
0

I got the same error - to add to @Tom Melo's answer, for others who are still asking. Since the error is trying to write where you are allowed to do so only in \tmp folder.

Dharman
  • 30,962
  • 25
  • 85
  • 135
0

Elaborating @Tom Melo's answer.

Try using https://docs.python.org/3/library/tempfile.html for creating temporary folders as it has bunch of added advantages and it works seamlessly inside the AWS lambda

SenthurLP
  • 124
  • 1
  • 7