ez4nick
ez4nick

Reputation: 10199

AWS Lambda shutil.move file to /tmp directory

I have an aws lambda and I am trying to move files to the /tmp directory so I can read/write them. I understand that the /tmp directory is the only one available with write access. I am trying to move the files with:

for file in os.listdir("/var/task/Files/"):
     shutil.move("/var/task/Files/"+file,"/tmp/")

And when I run the lambda it gives the following error:

    [ERROR] OSError: [Errno 30] Read-only file system: '/var/task/Files/700.in'
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 13, in lambda_handler
    rs.run()
  File "/var/task/Files/run.py", line 10, in run
    shutil.move("/var/task/Files/"+file,"/tmp/")
  File "/var/lang/lib/python3.8/shutil.py", line 812, in move
    os.unlink(src)

Is there something I am missing in order to accomplish this correctly?

Upvotes: 1

Views: 1165

Answers (1)

Anon Coward
Anon Coward

Reputation: 10823

As you said, only the /tmp file system is mounted read+write.

     shutil.move("/var/task/Files/"+file,"/tmp/")

You're attempting to modify the directory under /var/task to move the file off of it. This is a read-only filesystem, so it'll fail. Copy the file instead:

     shutil.copy("/var/task/Files/"+file,"/tmp/")

Upvotes: 3

Related Questions