Closed simonB2020 closed 2 years ago
Hi, I am having a similar issue, did you find anything?
Your problems are that you may not be using the Linux version of Psycopg. That is the execution environment for Lambdas. Also, be sure you are using the Python 3.8 runtime for Lambda, not the newer 3.9.
Trying to add psycopg as a lambda layer. My local machine is windows, so i cannot build anything myself, so trying to use the precompiled sources with static refs. Getting 'No module named 'psycopg2' at runtime.
Adding my steps here in the hope someone can spot what I am doing wrong ? Thanks
Steps:
(i)Copy source files: Copy folder : psycopg2-3.8 To: C:.......\lambda-src\psycopg2-3.8 Rename To: C:.......\lambda-src\psycopg2
(ii) zip psycopg folder data "archive_file" "zip_psycopg2" { type = "zip" source_dir = "${path.module}/lambda-src/psycopg2" output_path = "${path.module}/lambda-zip/psycopg2.zip" }
(iii) create layer resource "aws_lambda_layer_version" "lambda_psycopg2_layer" { layer_name = "xxx-lyr-psycopg2${local.ap_suffix}" filename = data.archive_file.zip_psycopg2.output_path source_code_hash = data.archive_file.zip_psycopg2.output_base64sha256 compatible_runtimes = ["python3.8"] }
(iv) associate layer & function resource "aws_lambda_function" "meta_rsxtendinfo" { ... filename = data.archive_file.zip_rsxtendinfo.output_path
source_code_hash = data.archive_file.zip_rsxtendinfo.output_base64sha256
runtime = "python3.8" layers = [aws_lambda_layer_version.lambda_psycopg2_layer.arn] }
(v) use import in function code Function code: import psycopg2
ERR: Unable to import module: No module named 'psycopg2'