简体   繁体   中英

aws lambda python exception

I am trying to run python code in AWS lambda and I got exception from aws lambda when I run test.

I don't understand what type of this exception. its first time for me.

 {
  "errorMessage": "The 'psycopg2>=2.5' distribution was not found and is required by the application",
  "errorType": "DistributionNotFound",
  "stackTrace": [
    [
      "/var/task/redshift_test.py",
      22,
      "handler",
      "print_meta_info('test_schema')"
    ],
}

here is my list of python3.6 library for run code.

.
├── redshift_sqlalchemy
├── sqlalchemy
├── SQLAlchemy-1.2.8.egg-info
├── sqlalchemy_redshift
└── sqlalchemy_redshift-0.7.1.dist-info

>> when I try pip freeze
psycopg2==2.7.5
SQLAlchemy==1.2.8
sqlalchemy-redshift==0.7.1

Psycopg2 is not a module that is available when executing Lambda functions in AWS. In fact, Lambda does not include ANY libraries in its AMI to communicate with a PostGreSQL database. In order to run the psycopg2 library, you will need to compile the C psycopg2 library code, reference it in a python file, zip it with your lambda function, and upload it to either S3 or Lambda directly.

Fortunately, some kind soul on the internet has already done this :) You can find his code here https://github.com/jkehler/awslambda-psycopg2 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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