Skip to content
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

[BUG] OpenCV Headless doesn't work with lambda #115

Open
Ryan-Daly opened this issue Sep 23, 2020 · 8 comments
Open

[BUG] OpenCV Headless doesn't work with lambda #115

Ryan-Daly opened this issue Sep 23, 2020 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@Ryan-Daly
Copy link

Describe the bug
OpenCV Headless isn't working with Lambda Layers. Getting an error:

{
  "errorMessage": "Unable to import module 'lambda_function': libgthread-2.0.so.0: cannot open shared object file: No such file or directory",
  "errorType": "Runtime.ImportModuleError"
}

Lambda function:

import json
import cv2

def lambda_handler(event, context):
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

Layer Version ARN:
arn:aws:lambda:eu-west-2:770693421928:layer:Klayers-python38-opencv-python-headless:11

Framework:
Console

@adriaanbd
Copy link
Contributor

adriaanbd commented Sep 25, 2020

Just tested it on us-east-1 and can confirm same error

image

image

@keithrozario
Copy link
Owner

I suspect it doesn't have opencv itself, and not just the headless bit. Let me check.

@adriaanbd
Copy link
Contributor

If I change the Python version to 3.7 it does say there is no module cv2
image

@keithrozario keithrozario added enhancement New feature or request bug Something isn't working and removed enhancement New feature or request labels Nov 10, 2020
@vliegenthart
Copy link

Are there perhaps any updates on this bug? I'm running into the same error for this layer

@keithrozario
Copy link
Owner

Sorry guys, haven't had time to look into this. Overall, we just pip install the package, and zip that up into a layer.

I suspect in order to use this, we'll need that shared-object file which isn't installed with pip. :(

@vliegenthart
Copy link

Gotcha, thank's for the heads up 👍

@tbarusseau
Copy link

I'm having the same issue.

opencv-python-headless depends on a native library (libglib), and AFAIK it's not possible to create a Lambda layer which installs system dependencies for Lambda.

Is there a workaround? I know that this exists, but generating a shared library on an Amazon Linux EC2 instance to ship it later in a ZIP archive for a Lambda function seems... Not very robust? I mean if that's the only way to get it to work, I'll try!

@keithrozario
Copy link
Owner

keithrozario commented Aug 8, 2021

FIX:

I created a new layer that contains the missing dependencies, would you mind testing it out.

The layer arn is:
arn:aws:lambda::770693421928:layer:Klayers-python38-libgthread-so:1

If you include both the opencv layer and the layer above, the error message no longer appears.

Screen Shot 2021-08-08 at 1 41 36 PM

more info here (for further reference):
https://www.keithrozario.com/2021/08/missing-so-files-in-lambda-functions.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants