0

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

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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
yes, just instead of upload.txt - use /tmp/upload.txt in both places

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.