8

I am using a docker container image on lambda to run my ML model. My lambda function has a S3 trigger to fetch images. I am trying to run my lambda function but I am getting this error. Can someone please help me?

error screenshot

PS - now i am aware /tmp is the only writable directory in lambda but how to solve this with that?

3 Answers 3

14

As others have mentioned, /tmp is the only writable directory in any AWS Lambda environments, either using containers or not.

Having said that, you should move your entire library (during the lambda runtime -- during container image build time doesn't work) to that directory -- such that everything remains connected within the library -- and then reference your new library directory in the library path environment for Lambda: LD_LIBRARY_PATH

Referencing your new library directory in the library path environment for Lambda should be done because Lambda looks at the /opt/ directory by default; and since you just moved your library to /tmp, you should also update LD_LIBRARY_PATH to contain that location. This can be done in the Dockerfile:

# Set the LD_LIBRARY_PATH
ENV LD_LIBRARY_PATH="/opt/my-lib-folder/:$LD_LIBRARY_PATH"

or during Lambda runtime:

os.environ['LD_LIBRARY_PATH'] = '/tmp/my-lib-folder:' + os.environ['LD_LIBRARY_PATH']

def lambda_handler(event, context):
   # your code ...

If there are still problems, it may be related to linking problems of your library, or that you didn't update your LD_LIBRARY_PATH correctly.

EDIT: As pointed out by @rok, you cannot move your libraries during the container image build time, because the /tmp folder will be erased by AWS automatically.

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

2 Comments

I want to add that I just faced the same issue and moving libraries to /tmp during image build is not a valid option because AWS clear that folder upon launching the instance and you end up with an empty folder and a file not found error. I didn't find any reference to this in the docs, but I experienced this and my solution was to use tmp folder only during the lambda execution.
@rok I didn't know that, so thank you for sharing this! I personally never had to move libraries to my /tmp folder because never needed them to be writable, but it's good to know that it wouldn't work. I will correct my answer.
4

The file system in a Lambda environment is read-only except for the /tmp directory.

3 Comments

Alright, so is it possible to move easyocr (library that i believe is causing error) to /tmp directory to solve this error?
Hey @Mark, is it possible to write to any path inside a container if I'm using lambda containers?
@AllanChua Please look at the docs: "The container image must be able to run on a read-only file system. Your function code can access a writable /tmp directory"
1

That error seems to be it trying to create its config/cache folders and failing. Essentially you need to specify the MPLCONFIGDIR environment variable to your container and set the value to a directory inside /tmp that is writable.

1 Comment

I have tried that but it only helps with the warning message, the error still persists

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.