Skip to content

dkobia/awslambda-psycopg2

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

psycopg2 Python 3 Library for AWS Lambda

This is a custom compiled psycopg2 C library for Python 3. Due to AWS Lambda missing the required PostgreSQL libraries in the AMI image, we needed to compile psycopg2 with the PostgreSQL libpq.so library statically linked libpq library instead of the default dynamic link.

This library is compiled with:

  • psycopg2 2.7.7
  • postgresql 10.7
  • Python 3.7

How to use

Copy the psycopg2 folder in the build folder into your AWS Lambda zip package.

Compile with different versions of libraries

Library needs to be compiled in amazon linux environment. Most likely you don't have the environment.

Solution? Docker!

  1. Install Docker.
  2. Download the PostgreSQL source code (.tar.gz), rename to postgresql.tar.gz and put it into sources folder.
  3. Download the psycopg2 source code (.tar.gz), rename to psycopg2.tar.gz and put it into sources folder.
  4. build image: make build
  5. run image: make run
  6. delete image if you don't need it anymore: make clean

custom compiled psycopg2 library is now in build folder.

Compile with SSL support

  • Change step 4 above to: make build SSL=1

Compile on Windows

makefile is not available on Windows, there're few options:

  • use cygwin - provide functionality similar to a Linux distribution on Windows.
  • use WSL - let developers run GNU/Linux environment on Windows 10.
  • run docker commands in makefile directly.

About

Python 3 + PostgreSQL 10 + psycopg2

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.7%
  • Other 0.3%