Using psycopg2 with Lambda to Update Redshift (Python)

前端 未结 7 1756
情深已故
情深已故 2020-11-27 19:36

I am attempting to update Redshift from a Lambda function using python. To do this, I am attempting to combine 2 code fragments. Both fragments are functional when I run the

7条回答
  •  北荒
    北荒 (楼主)
    2020-11-27 19:51

    I just came across this same problem. I stumbled across the same github project that was noted in the other answer which explained the problem as follows:

    Due to AWS Lambda missing the required PostgreSQL libraries in the AMI image, we needed to compile psycopg2 with the PostgreSQL libpq.so library statically linked libpq library instead of the default dynamic link.

    This has been noted in the previous answer, and I started to follow the instructions to build myself a version of psycopg2 with a statically linked PostgreSQL library. I found a much easier option though. I noticed on the psycopg2 github page the following:

    You can also obtain a stand-alone package, not requiring a compiler or external libraries, by installing the psycopg2-binary package from PyPI:

    $ pip install psycopg2-binary

    The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources.

    When I pip installed the psycopg2-binary package and included it in my requirements.txt file I was able to connect to my postgresql database from a lambda function flawlessly. I am using chalice which I highly recommend. I realize that psycopg2 recommends not using the binary version for production, but I don't see a huge difference between using the binary version or compiling and statically linking it yourself. Someone please correct me if I'm wrong on that.

提交回复
热议问题