error while uploading python zip file with psycopg2 to aws lambda - python

I'm trying to add the python zip files to was lambda which contains psycopg2 files in it.I'm getting an error. please try to help
"errorMessage": "Unable to import module 'handler': libpq.so.5: cannot open shared object file: No such file or directory",
"errorType": "Runtime.ImportModuleError"

The point is psycopg2 depends on native code (libpq.so) and your zip file does not contain this dependency.
See here for a solution
Another option is pip install psycopg2-binary. See here for details.

Related

Cant import local module

So I am trying to use this repository on my computer but I cant seem to import a local module (Agent.pyx) and use functions from that file. The error I get is:
ModuleNotFoundError: No module named 'RLAgent.Agent
Screenshot of error
Link to repository
You have to install the package manually
Since Agent.pyx is a .pyx file, you will need to first build it. The README file in the linked repo also mentions this. So you need to move to the RLAgent directory and execute the setup instruction as:
cd RLAgent
python3 setup.py build_ext --inplace
This will build the required .c and .so file which will then enable it's import in other files such as Train.py which is where the import is throwing an error.

AWS Lambda - error on importing pymssql (module not found)

Goal is to connect and query SQL Server instance via Lambda's Python code that has following structure:
I tried two configs but both leave me with error:
Option 1: pymssql listed in package/python/requirements.txt
datadog-api-client>=1.6.0
pyodbc>=4.0.32
pymssql>=2.2.2
Option 2: adding lib to zip file as shown here:
Both throw error:
[ERROR] Runtime.ImportModuleError: Unable to import module 'function': No module named 'pymssql._pymssql'
impport cython made it much easier then pip install pymssql to the directory.

no module named portaudio aws lambda

I currently have some python code that I have stored in a zip file with my dependencies. The code compiles and works fine locally in Visual Studio Code. However, when I go to upload the file onto a Lambda function, I get this error:
{
"errorMessage": "Unable to import module 'lambda_function': No module named '_portaudio'",
"errorType": "Runtime.ImportModuleError",
"stackTrace": []
}
I am using pyaudio and I have never had any interaction with portaudio. What should I do?
Attached is a screenshot of my zip file:
Image Updates

"Unable to import module 'lambda_function': libasound.so.2: cannot open shared object file: No such file or directory",

I have created a lambda layer with the following python packages using pip3:
google-cloud-texttospeech and
azure-cognitiveservices-speech
When I use this layer with python3.8 lambda function, I get the error saying,
{
"errorMessage": "Unable to import module 'lambda_function': libasound.so.2: cannot open shared object file: No such file or directory",
"errorType": "Runtime.ImportModuleError"
}
I removed the azure-cognitiveservices-speech package and the layer works fine with lambda. This means that the culprit is the azure-cognitiveservices-speech package. I couldn't find a way to solve the problem.
Any kind of help will be grately appreciated. Thank you!
So you need to install the package manually on your system and package the same with your lambda zip file as per the documentation
Once installed you can package your python code and the .so files together and upload to AWS lambda. The folder structure for your reference should look like this.
myawesomefunction.py
libasound.so.2

Serverless AWS Lambda : no module named `secret_manager`

Installed serverless-python-requirements using npm.
I use secret-manager library in handler.py
I am able to successfully deploy lambda function using serverless (no errors).
I have secret-manager listed (along with other pypi packages) in requirements.txt
In order to package it, I include following lines in serverless.yml
pythonRequirements:
dockerizePip: true
To verify if secret-manager is packaged with the other PyPi binaries:
I downloaded the deployed lambda as a zip file and verified it does have secretmanager along with other pypi binaries.
But, still for some reason, it still fails saying secret-manager module not found..
{
"errorMessage": "Unable to import module 'handler': No module named 'secret_manager'",
"errorType": "Runtime.ImportModuleError"
}
Note the name of folder of PyPi is secretmanager and the name of file inside it is secret_manager.py
For reference :
I forgot to include a separate user-written file secret_manager.py that had the logic for getting secret from secret-manager. It had nothing to do with the PyPi binary.

Categories

Resources