4

I get the following error

{
  "errorMessage": "[Errno 30] Read-only file system: '/home/sbx_user1051'",
  "errorType": "OSError",
  "stackTrace": [
    "  File \"/var/lang/lib/python3.8/imp.py\", line 234, in load_module\n    return load_source(name, filename, file)\n",
    "  File \"/var/lang/lib/python3.8/imp.py\", line 171, in load_source\n    module = _load(spec)\n",
    "  File \"<frozen importlib._bootstrap>\", line 702, in _load\n",
    "  File \"<frozen importlib._bootstrap>\", line 671, in _load_unlocked\n",
    "  File \"<frozen importlib._bootstrap_external>\", line 843, in exec_module\n",
    "  File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed\n",
    "  File \"/var/task/app.py\", line 3, in <module>\n    nltk.download('stopwords')\n",
    "  File \"/var/task/nltk/downloader.py\", line 777, in download\n    for msg in self.incr_download(info_or_id, download_dir, force):\n",
    "  File \"/var/task/nltk/downloader.py\", line 642, in incr_download\n    yield from self._download_package(info, download_dir, force)\n",
    "  File \"/var/task/nltk/downloader.py\", line 699, in _download_package\n    os.makedirs(download_dir)\n",
    "  File \"/var/lang/lib/python3.8/os.py\", line 213, in makedirs\n    makedirs(head, exist_ok=exist_ok)\n",
    "  File \"/var/lang/lib/python3.8/os.py\", line 223, in makedirs\n    mkdir(name, mode)\n"
  ]
}

when testing my lambda function. I don't understand what this error is telling me to do about the docker image I am using, if that even is the correct route to explore. What should I do

1
  • Can you describe in more detail what you are trying to do? What does your Dockerfile look like? As Mark B mentioned, the docker image is trying to write to /home/sbx_user1051 but I suspect you are probably not doing this explicitly, rather it's some command behind it, and I'm curious which one it is. Has it something to do with RUN apk ...? Commented May 1, 2023 at 12:40

2 Answers 2

11

AWS Lambda is not a generic docker runner. The docker containers you deploy to Lambda have to comply with the AWS Lambda runtime environment.

The docker image you are using is trying to write to the path /home/sbx_user1051 apparently. On AWS Lambda the file system is always read-only except for the /tmp path. You will have to modify the code running in the docker image to prevent it from writing anywhere else but /tmp/.

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

9 Comments

Is there a different way to get the docker image to work without having to change my code so that it reads from tmp?
@vecohah you should read the Prerequisites here docs.aws.amazon.com/lambda/latest/dg/images-create.html. As Mark says The container image must be able to run on a read-only file system. Your function code can access a writable /tmp directory with between 512 MB and 10,240 MB, in 1-MB increments, of storage.. Lambda is not a container runtime engine, if you want to just run a container then maybe use ECS
@MarkB sadly I cannot ask question anymore on Stack.
You can try to configure a HOME variable on the Lambda set to /tmp. This has worked for me in some scenarios but it may break other things if you need to read stuff from the (actual) home directory.
@mreferre a wonderful and dangerous idea - i love it
|
3

According to these EasyOCR source files: https://github.com/JaidedAI/EasyOCR/blob/c999505ef6b43be1c4ee36aa04ad979175178352/easyocr/config.py#L4 https://github.com/JaidedAI/EasyOCR/blob/c999505ef6b43be1c4ee36aa04ad979175178352/easyocr/easyocr.py

The directory that is going to store the files generated by the library during its runtime is defined by the MODULE_PATH variable from this 'EasyOCR/easyocr /config.py' file, that is reused by the defined environment variables EASYOCR_MODULE_PATH and MODULE_PATH.

I had the exact same problem as you, what I did to work it around was defining these variables values before importing the library itself, this way when it's imported the files are going to be loaded/installed to the path you want and defined previously.

import os

os.environ["EASYOCR_MODULE_PATH"] = "/tmp"
os.environ["MODULE_PATH"] = "/tmp"

import easyocr

Comments

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.