Couldn't find path to unrar library in aws lambda (Python)

468 views Asked by At

I have a rar file, which I want to unrar in AWS lambda using python. I learned about unrar library in python. I have created the layer for unrar in AWS. But now when I execute the code

from unrar import rarfile
rar = rarfile.RarFile('file.rar')
rar.extractall()

I got the following error

Couldn't find path to unrar library.

I read the solution. According to the solution, I have to set the environment variable. can I use this solution for AWS Lambda also? and what other solutions can be possible.

1

There are 1 answers

0
Vikku On

Firstly, I followed documentation of unrar. Steps I followed

  1. download source file, unzip it. (it will create a folder say unrar)
  2. cd unrar (go to folder)
  3. make lib && make install-lib
  4. it will create libunrar.so file at /usr/lib location in linux.

Python unrar could not find this file in Linux path, which is why It was throwing Couldn't find path to unrar library.

Now, I created a lambda layer for this file.

  1. create a folder named lib and copy/paste this libunrar.so in that folder.
  2. create a zip of lib and upload it to a lambda layer
  3. attach this layer to your lambda

Finally, set an environment variable in lambda UNRAR_LIB_PATH to libunrar.so