0

I am trying to write to my PostgreSQL database with AWS Lambda using the python2.7 runtime. I care very little about how I do this, so if anyone has a different way that I can understand that works, I'd love to hear it.

The method I'm currently trying is to use psycopg2, as this is the only way I know. In order to do this, I need to upload the psycopg2 module to my environment on AWS Lambda. As per instructions, I've created a directory with my source and psycopg2 using pip install psycopg2 -t ..\my-project, zipped my-project, and uploaded it.

My error message is this from within the AWS Lambda console: Unable to import module 'lambda_function': No module named _psycopg

The code runs on my windows machine. I think the issue is that when I import psycopg2 from my local windows machine, the _psycopg module is being imported from _psycopg.pyd, and .pyd files are windows specific. I may be wrong about this.

I'm really just looking for any way to achieve the desired result described in my first paragraph, but here's a more specific question: How do I tell windows to pip install and compile psycopg2 without using .pyd files? Is this possible? Do I have something completely wrong?

I know the formatting of this question is a little unorthodox, I think I've given all the necessary information, let me know if there's anything else I can provide.

3
  • You need to install the package using pip for whatever architecture AWS Lambda uses: docs.aws.amazon.com/lambda/latest/dg/… Commented Mar 7, 2018 at 21:25
  • Do you know how to do this using a windows machine? Commented Mar 7, 2018 at 21:27
  • Is the best way to just use a virtual machine running linux? Commented Mar 7, 2018 at 21:30

1 Answer 1

1

I solved the problem by opening an ubuntu instance on VirtualBox, pip installing the package there, pulling the relevant folders out, and placing them in my-project before zipping and uploading to AWS Lambda.

See these instructions.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.