How to Install Custom Python Packages or psycopg2 in AWS Lambda Function

preview_player
Показать описание
In this tutorial I will show, how to install psycopg2 or custom python packages into the AWS Lambda function step by step. It is will be useful for understanding about AWS Lambda Layers.
Just by following instructions and give the command step by step.

1. sudo amazon-linux-extras install python3.8

4. sudo python3.8 -m pip install psycopg2-binary -t python/

Happy Coding :)
Рекомендации по теме
Комментарии
Автор

Mate, I have been trying for almost 12 hours (not 3 days like you) and then I found your video - thanks!!! Good work :-)

DusanMondek
Автор

This was very helpful. I also had spent days trying to get psycopg2 to work and this worked right away.

ericland
Автор

Awesome tutorial! I finally got psycopg2 working in my lambda function, huge thank you!

davidc
Автор

Now I get error "No module named 'psycopg2._psycop".
Reason was that I was using Python 3.13. Once I created a Python 3.8 Lambda, it all worked.

MM-slmo
Автор

After following all the steps I'm getting error
{
"errorMessage": "Unable to import module 'test_lambda': No module named 'psycopg2._psycopg'",
"errorType": "Runtime.ImportModuleError",
"requestId": "6a8e278e-c38b-4bcf-9a13-ce814c1f0434",
"stackTrace": []
}

Any help ?

castlemaster
Автор

thanks u a lot, u save my dayy... keep going bro

tuvoxuan
Автор

thank you so much. spent the day trying out different ways to solve this problem, this one worked like a magic.

just one question, everytime I have to add another python library to AWS Lamda, do I need to this everytime (create cloud9 env, install dependencies inside the env, and so on)?

armielgonzzz
Автор


But, neither command works for python3.10:
ec2-user:~/environment $ sudo amazon-linux-extras install python3.10
Topic python3.10 is not found.

ec2-user:~/environment $ sudo python3.10 -m pip install psycopg2-binary -t python/
sudo: python3.10: command not found

Edit: the solution was
sudo /usr/local/bin/python3.10 -m pip install psycopg2-binary -t python/

Full explanation: Path Environment Variable: When you run sudo, the environment variables, including PATH, might be reset or different from your user's environment. This means that while python3.10 is accessible to your user (as shown by python3.10 --version working), it may not be in the PATH accessible to the superuser.

thebooktutor
Автор

in my case it says:

{
"errorMessage": "Unable to import module 'lambda_function': No module named 'psycopg2._psycopg'",
"errorType": "Runtime.ImportModuleError",
"requestId": "8cf6e202-38bf-458f-9347-2ead4009fb13",
"stackTrace": []
}

Function Logs
START RequestId: Version: $LATEST
[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'psycopg2._psycopg'
Traceback (most recent call last):END RequestId:
REPORT RequestId: 3.28 ms Billed Duration: 4 ms Memory Size: 128 MB Max Memory Used: 35 MB Init Duration: 85.96 ms

ChinSamatov
Автор

how to install the same for Python3.10 as i received the below error while install Python3.10

$ sudo amazon-linux-extras install python3.10
Topic python3.10 is not found.

FernandesReegan
visit shbcf.ru