AWS LAMBDA "errorMessage": "[Errno 30] Read-only file system: 'drive-python-quickstart.json'" AWS Lambda“错误消息”:“[Errno 30]只读文件系统:'drive-python-quickstart.json'”

16

我在AWS Lambda中遇到了Google Drive凭证的问题,在部署我的.zip文件后,在本地机器上调用函数之前,一切正常,但在将zip部署到AWS后约30分钟后,我会遇到Lambda函数错误。

  "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')"
    ]
  ]
}

在文件file.py中,我有如下代码:

 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)

我尝试将f = open(self._filename, 'w') 设置为 'r',但这没有帮助,也许有人知道我该如何修复它?请建议。

3个回答

41

显然,您正在尝试在不允许的位置编写文件。Lambda目前仅支持将文件写入/tmp目录。


1
你能分享一下你是怎么解决的吗?我现在也遇到了这个问题 - @Andrej - Geetha Ponnusamy
我刚刚把所有的证书文件放到了.zip文件中,并将目标设置为项目目录。 - Андрей Ка
我也做了同样的事情,将所有文件放在.zip中并上传到s3,然后在lambda中使用该s3链接。在这种情况下,我得到了“errorType”:“IOError”,“errorMessage”:“[Errno 30]只读文件系统:'drive-python-quickstart.json'”。有什么建议如何解决这个问题!提前致谢。 - Geetha Ponnusamy
你怎么解决的?我在 /tmp 文件夹中创建一个文件并尝试将其上传到 EC2 时仍然收到错误 - [Errno 30] 只读文件系统:'1587472029.zip'。 - Vikramsinh Gaikwad
如果有人遇到这个问题,在您的 Lambda 函数目录中创建一个名为 tmp 的文件夹,然后将要写入的文件路径更改为 /tmp/FILE - yudhiesh

0

0

我遇到了同样的错误 - 补充一下@Tom Melo的答案,对于那些仍在询问的人。由于该错误试图在只能在\tmp文件夹中进行写入的位置进行写入。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接