-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support to load library externally #40
Comments
Having the same issue with my app deployed on Heroku. Any word on the status of the PR? |
I have the same issues with AWS ec2. Don't know how to assign a path |
Apologies for this problem (and for my rather late response). Thanks very much for the PR. I have merged to feature/40-path-to-zbar, where I will add unit tests and make other changes. I have no experience of AWS nor or Heroku. Where does The behaviour of |
Hi, In case of AWS ec2, the library is installed by instance owner, in other hand in heroku and others managed application server, the library get installed in a given docker image or can be load from disk, thus in second case you can embed the lib in application code and load it at run time. The PR I had pushed, add the option to load the library from any path to handle cases where the installation is not a responsibility of the developer. |
OK thanks. It would be good to use the standard mechanisms for finding the library unless there really is no other option. Do these platforms really not make the shared lib location available on |
Does anyone have an example of how they got this to work with a Lambda function in AWS? I am installing pyzbar in the packaged deploy of my lambda but still getting issues about the zbar shared library. |
Can't speak for AWS lambda, but deploying to an Amazon Linus 2.8: Adding the
This is the equivalent of Deployment was successful after this and desired functionality via pyzbar was working. |
If anyone still has problems using the library to work with heroku, take a look at this. I described my example setup heroku app. |
I'm gonna leave this for posterity. In alpine it seems the libzbar gets installed as Here's the complete line for docker alpine
|
@sebastiandev hey there! Looks very interesting. Any idea how to make an AWS lambda layer? The one you use is based on alpine, so it's a bit different for AWS. I did some research and tried the following: Creating a file FROM amazonlinux
RUN yum update -y
RUN yum install -y gcc gcc-c++ make
RUN yum install -y wget
RUN yum install -y tar
RUN yum install -y bzip2
RUN mkdir /lambda-DecodeQR
RUN wget https://jaist.dl.sourceforge.net/project/zbar/zbar/0.10/zbar-0.10.tar.bz2
RUN tar -jxvf zbar-0.10.tar.bz2
RUN cd zbar-0.10 && ./configure --build=x86_64 --prefix=/lambda-DecodeQR CPPFLAGS=-I/usr/include --with-libiconv-prefix=/usr/include --with-python=no --with-libiconv-prefix=/usr/include --without-imagemagick$
RUN ln -s /usr/lib/libzbar.so.0 /usr/lib/libzbar.so
RUN yum install -y zip
RUN yum -y clean all
RUN zip -gr DecodeQR.zip share lib64 lib include bin Then running the following commands: docker build -t amzlinuxpy .
docker run -it amzlinuxpy bash # let this run in another tab
docker ps # change the XXX_ID_XXX below and match it with the container ID you see with this command
docker cp XXX_ID_XXX:/DecodeQR.zip DecodeQR.zip Not proud on the This zip contains the libraries of zbar, that should work on AWS Lambda inside a Lambda layer. I have no clue what to with this now, because I just learned about AWS Lambda today and I don't understand docker layers completely. I think https://hackernoon.com/how-to-deploy-aws-lambda-with-docker-containers-e51j3141 might be an interesting article to look at for continuing this journey. Any feedback is welcome, if this is not relevant anymore for you, feel free to yeet it with a 🚀 emoji I guess :) Might also be interesting for @novomotus, @cmendesce, @3Mcolab because they reference AWS too. |
[EDITED] In part to answer the question from @vincentcox, but also to re-open this thread, getting pyzbar under AWS Lambda to load a library provided by the user is extremely hard, specifically because this proposed patch did not get used. The problem is that the way that On older versions of Lambda there was an ugly, sub-optimal work-around to this problem that @vincentcox is facing involving linking All in all it would be hugely better if we could just explicitly provide the file path and avoid having to build a complete Docker image just to deploy a Python function that uses As a final note, I believe that @vincentcox 's script above for building the zbar library may not work as required because the current version on |
Thank you @nickovs for providing the script for building the Zbar library for AWS Lambda. I followed your gist and generated three libraries |
@felixb-dev Yes, those sizes are what I get. Note that the first two are just soft links; the third file is the real library. As for how to use the library, right now you need to apply the patch in #41 to your own copy of pyzbar and include the patched version in the code you deploy in Lambda. Hopefully the patch will get merged onto the master branch and released to PyPI at some point soon, but we need some contributor like @quicklizard99 to do that. |
@nickovs Thanks a lot for all your research around this. I would also love to have this PR merged into master. Would help a lot. Or have something like pdf2image package has where you can set the poppler_path in the function. I'm still pretty fresh on both python and lambda. I have run the script from your gist and added the .so files as a layer. I have forked the repo and added your #41 patch and pulled that repo into my function and set the ZBAR_PATH env variable to the correct in my layer. How can I now import this package? The file structure is:
I have tried in my app.py with Thanks a lot and really hope that @quicklizard99 or some other contributor look at this again. Would be very helpful to be able to set the zbar path somehow. |
@MarGul What I did was copied the inner
If you do this then you should be able to just use |
Thanks a lot @nickovs . I had to update the
All is working now. I have the libzbar.so as a Layer instead. Thanks a lot for your help. Hope this issue get's resolved soon. |
@MarGul do you have a repo on how to make the the library work with layers? I only manage to get it working if I uploaded it with the lambda function code, but can't manage to get it working as a Layer 😢 |
I've tried following everything from above and I'm still not getting the zbar library found. Was a layer's path ever worked out? If not, a bundled .zip file? I've tried both. I've tried patching the zbar_library.py based on #41 and I've compiled and put the libzbar.so in a bundle, in a layer, etc...... I'm working perfectly in windows or ubuntu. But I cant get past here on aws lambda. import json |
@andrologixx I managed to take a bit of everyone's help on this issue, and created the following repository to create your own Lambda Function working with pyzbar. |
I'm using AWS SAM to create my function and resources. This is in my
The important part here is the
My Hope this helps. |
Hi @nickovs, How do I get a libzbar.so file for AMI-2 (CentOS 7 based image)? It looks like you're using ubuntu based .so file. |
@souravjamwal77 The gist script I posted builds the library for running on AWS Lambda instances, which run a Red Hat derived Linux, but if you need a copy for Centos7 you can just replace the Docker image name |
I used the following solution for AWS, it's using a layer approach, which is a little different from @MarGul :
Template file:
|
For anyone attempting to get a standalone AWS layer, I was able to do so by using the following Dockerfile which follows the same approach from @DanyStinson above. Uploading pyzbar_layer.zip directly to an AWS layer worked correctly for me.
|
As pyzbar is a very usable library to handle images, some applications wants to handle images in a very scalable context like serverless platforms (aws lambda, azure function and so on). These platforms run workloads on top of default environments that is not easy to customize to add a shared lib as pyzbar requires.
So, my suggestions is to add a new try during the load library function in
pyzbar/zbar_library.py
. The code below is showing only trying get the library in PATH, but a good try is find the library in a specific env var likeZBAR_PATH
.The text was updated successfully, but these errors were encountered: