Reputation: 25
I am trying to read data from PDF stored in S3 bucket, convert it to text and then dump these text into json file.
Finally I want to upload this json file to elastic search for indexing.
I have written below code snippet for doing this:
with open('data.json','w') as f:
json.dump(doc,f)
dataj=json.load(f)
doc_data=dataj[:]
doc
is the text which I have extracted using pdfminer.
when executing this code I'm getting below error.
[Errno 30] Read-only file system: 'data.json': IOError
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 56, in lambda_handler
raise e
IOError: [Errno 30] Read-only file system: 'data.json'.
Someone please help me in finding what I'm doing wrong here.
Upvotes: 2
Views: 4479
Reputation: 3092
You're trying to write a file where is not permitted.
Lambda currently only supports writing files to the /tmp directory.
with open('/tmp/data.json','w') as f:
json.dump(doc,f)
dataj=json.load(f)
doc_data=dataj[:]
Upvotes: 3