-1

I am developing a lambda function that needs to write each element of a list 'my_list', in a line of my 'upload.txt' file.

I have used the next code :

my_list=['hello', 'world', 'good', 'morning']
with open("upload.txt", "w+") as a_file:
   for item in my_list:
       a_file.write("%s\n" % item)
   file_dict = {"upload.txt": a_file}
   response = requests.post(url, files=file_dict)

When I try to test my lambda it gave me the next error:

"errorMessage": "[Errno 30] Read-only file system: 'upload.txt'",
"errorType": "OSError",

It is strange because I will create that file now so why it is written read only file

baddy
  • 369
  • 1
  • 3
  • 23
  • Does this answer your question? [Error "Read-only file system" in AWS Lambda when downloading a file from S3](https://stackoverflow.com/questions/39383465/error-read-only-file-system-in-aws-lambda-when-downloading-a-file-from-s3) – Ermiya Eskandary Jun 08 '22 at 10:51

1 Answers1

1

It actually doesn't allow you to write it; just use /tmp/ directory to write temporary files for lambda. Just remember the files in /tmp are not always cleaned in concurrent run of lambdas.

Marek Knappe
  • 422
  • 2
  • 7
  • means I need to add ´/tmp/´ to ´upload.txt´ path? it is strange because if I used only one element to write in this file it works fine but a list with many elements no – baddy Jun 08 '22 at 09:19
  • 1
    yes, just instead of upload.txt - use /tmp/upload.txt in both places – Marek Knappe Jun 08 '22 at 09:21