Skip to main content

psycopg2 Python Library for AWS Lambda

This is a custom compiled psycopg2 C library for Python. 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.I am just using the follwing git source and uploaded to https://pypi.org/

Install and setup

pip install aws-psycopg2

Source code : https://github.com/jkehler/awslambda-psycopg2/tree/master/psycopg2

Instructions on compiling this package from scratch

Here was the process that was used to build this package. You will need to perform these steps if you want to build a newer version of the psycopg2 library.

  1. Download the PostgreSQL source code and extract into a directory.
  2. Download the psycopg2 source code and extract into a directory.
  3. Go into the PostgreSQL source directory and execute the following commands:
  • ./configure --prefix {path_to_postgresql_source} --without-readline --without-zlib
  • make
  • make install
  1. Go into the psycopg2 source directory and edit the setup.cfg file with the following:
  • pg_config={path_to_postgresql_source/bin/pg_config}
  • static_libpq=1
  1. Execute python setup.py build in the psycopg2 source directory.

After the above steps have been completed you will then have a build directory and the custom compiled psycopg2 library will be contained within it. Copy this directory into your AWS Lambda package and you will now be able to access PostgreSQL from within AWS Lambda using the psycopg2 library.

Release files for awslambda-psycopg2 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for awslambda-psycopg2 1.0.2
File Size Uploaded
awslambda-psycopg2-1.0.2.tar.gz 34.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for awslambda-psycopg2 1.0.2
File Interpreter ABI Platform
awslambda_psycopg2-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 77.4 kB

Release files / awslambda-psycopg2-1.0.2.tar.gz

Download URL awslambda-psycopg2-1.0.2.tar.gz
Size 34.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8426f35ee860e787b0dd68bc1f12d47e051f1944e34cefc874d11e46fe446c2c
BLAKE2b-256 checksum
How to use checksums
6fd829d5b4978f320b530071850ab5c00cdd5ffbf15cc6dad1adf6b9c3096ead
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

Release files / awslambda_psycopg2-1.0.2-py3-none-any.whl

Download URL awslambda_psycopg2-1.0.2-py3-none-any.whl
Size 43.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a10d824b498c3fb9d7703eaaffbdf5c675b379f326a0fdb969252801e8a9731
BLAKE2b-256 checksum
How to use checksums
2b00f4a787233ed55e7339f0f5450f40cc11e5db62e8b85f12d6deaaa1902151
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page