简体   繁体   English

如何在 AWS lambda ZC1C425268E68385D1AB50741C 中为 PostgreSQL 安装 psycopg2 库在 python 中

[英]How to install psycopg2 libary in python for PostgreSQL in AWS lambda function?

I tried to deploy the package which had psycopg2 library in it to AWS lambda function i'm getting no module error, I have tried this from windows environment which I know is not compatible to aws environment. I tried to deploy the package which had psycopg2 library in it to AWS lambda function i'm getting no module error, I have tried this from windows environment which I know is not compatible to aws environment. can anyone help me out on installing the psycopg2 and process of deploying into AWS lambda function.谁能帮我安装 psycopg2 和部署到 AWS lambda function 的过程。 I'm new to AWS.我是 AWS 新手。 TIA TIA

AWS Lambda's are missing some postgres libraries, and the standard psycopg2 library will not work. AWS Lambda 缺少一些 postgres 库,并且标准 psycopg2 库将不起作用。

A solution to this is to use a different psycopg2 library from here - https://github.com/jkehler/awslambda-psycopg2 inside of your project, instructions on how to add it as a package within AWS Lambda are in the repo.对此的解决方案是在您的项目中使用不同的 psycopg2 库 - https://github.com/jkehler/awslambda-psycopg2 ,有关如何将其添加为 AWS Lambda 中的包的说明位于 repo 中。

  1. Build the layer package using the structure "python/lib/python3.9/site-packages".使用结构“python/lib/python3.9/site-packages”构建层 package。

  2. After installing psycopg2-binary, rename the _psycopg.so file under the directory "psycopg2" ("_psycopg.cpython-39-x86_64-linux-gnu.so "is under the "psycopg" directory).安装 psycopg2-binary 后,将“psycopg2”目录下的_psycopg.so文件重命名(“_psycopg.cpython-39-x86_64-linux-gnu.so”在“psycopg”目录下)。

  3. Put the layer into the Python lambda function and add it to the code.将图层放入 Python lambda function 并添加到代码中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM