10

I'm trying to use asyncpg with AWS Lambda and got next error when trying to import asyncpg

Unable to import module 'handler': No module named asyncpg.protocol.protocol'

I import python dependencies like at this answer with and without virtual environment.

upd. Found this repo with custom compiled psycopg2 what works good with AWS Lambda but for asyncpg don't found such alternative or instruction on compiling Lambda-friendly asyncpg package.

styvane
  • 59,869
  • 19
  • 150
  • 156
chinskiy
  • 2,557
  • 4
  • 21
  • 40

2 Answers2

4

This library has c-bindings and lambda does not play nicely with those. The main way to handle it is to upload the specific library with its bindings precompiled for Linux environments. The main way to is to follow the instructions here and make sure that the library it already compiled in your linux ( or mac I guess ). This would easily happen by just creating a venv and including it as the above guidelines suggest. You can find a similar problem here. In general, this is a common and frameworks like chalice try to find some workarounds.

0

write your code under the def lambdahandler() and also import all libraries and function below this function.