2

I am trying to run my flask app to lambda. It deploy successfully (using serverless framework) but when I'm testing I get this error :

OSError: [Errno 30] Read-only file system

Part of the code that trigger the error :

with open("tmp/some-file.zip", "wb") as binary_file:
        binary_file.write(file_content)

Any suggestion ?

John doe
  • 3,680
  • 7
  • 31
  • 65
  • Have you tried using a filesystem that you're allowed to write to? – Karl Knechtel Mar 23 '21 at 08:27
  • The app is already deployed to lambda. So what's wrong with the permission ? – John doe Mar 23 '21 at 08:28
  • Does https://stackoverflow.com/questions/53810516/getting-error-aws-lambda-erofs-read-only-file-system-open-var-task-assets help? I found it by putting `aws-lambda read-only file system` into a search engine. It was the first result. – Karl Knechtel Mar 23 '21 at 08:31
  • Looking closer: it appears that you know that you need to write to somewhere in the `/tmp` directory, but that means you simply have a typo (or a misunderstanding about absolute vs. relative paths on unix-like systems). – Karl Knechtel Mar 23 '21 at 08:32

1 Answers1

1

In the provided example, you're using relative path to tmp, unless you're working dir is /, it will try to open a file in an invalid (not available for write) path. When trying to write to a file in /tmp (which is writable for Lambdas), ensure you're providing proper, ideally absolute path.

pgrzesik
  • 1,869
  • 13
  • 14