Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

psycopg2 does not work with Serverless framework deployment on AWS Lambda

Tags:

I am trying to make a lambda function connect to Redshift, and deploy the same via The Serverless Framework.

serverless.yml config:

pythonRequirements:
    dockerizePip: non-linux
    dockerFile: ./Dockerfile

Dockerfile:

FROM lambci/lambda:build-python3.6
RUN yum install -y postgresql-devel postgresql-libs

requirements.txt

psycopg2==2.8.5
requests==2.22.0
boto3==1.9.234

Deployment is done via:

sls deploy --function fn_name --force

AWS Lambda gives an error:

libpq.so.5: cannot open shared object file: No such file or directory

And I can confirm that it is missing, but when I test the same with local docker image, the file is present. I'm still unsure on how serverless actually deploys the package

I do not want to use psycopg2-binary and I'm still unsure about aws-psycopg2, any suggestions on how to get the code to run?

like image 980
piyush daga Avatar asked Jul 01 '20 16:07

piyush daga


1 Answers

You can try using this module instead of default one (Supports only Python3.x)

https://pypi.org/project/aws-psycopg2/

While the above is not actively maintained, and has the max version as psycopg2==2.8.4, it could serve the use-case you might have.

You can also try zipping and uploading the package from here https://github.com/jkehler/awslambda-psycopg2 if you need support for older python versions.

like image 162
Sumit Avatar answered Oct 02 '22 14:10

Sumit