This gist is meant to show how to build psycopg2 for use in an AWS Lambda function using Docker. It is influenced by https://github.com/jkehler/awslambda-psycopg2.
-
Edit the version environment variables at the top of the Dockerfile as needed.
-
Build the docker image using
docker build -t lambda-psycopg2:latest .in the directory with the DockerFile. -
Once the docker image is created, start the container using
docker run -it lambda-psycopg2:latest /bin/bash. In this terminal, you can navigate to the/var/outputdirectory to inspect the psycopg2 package. -
While the container is running, in a separate terminal, copy over the resulting psycopg2 package to the host machine using
docker cp <container id>:/var/output/psycopg2 .The container ID can be obtained usingdocker container ls. -
Terminate the container by exiting the running shell.
Note: If you want to build psycopg2 with ssl, uncomment the # build postgres with ssl
section and the following sed line:
sed -i 's/libraries =/libraries = ssl crypto/g' setup.cfg
and comment out the # build without ssl section.