Home > Mobile >  Writing a list to a txt file with Python and AWS lambda
Writing a list to a txt file with Python and AWS lambda

Time:06-09

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

CodePudding user response:

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.

  • Related