├── 3.6 ├── .gitignore ├── Dockerfile ├── build.sh ├── serverless.yml └── setup.cfg ├── 3.7 ├── .gitignore ├── Dockerfile ├── build.sh ├── serverless.yml └── setup.cfg ├── 3.8 ├── .gitignore ├── Dockerfile ├── build.sh ├── serverless.yml └── setup.cfg ├── 3.9 ├── .gitignore ├── Dockerfile ├── build.sh ├── deploy.sh ├── serverless.yml └── setup.cfg └── README.md /3.6/.gitignore: -------------------------------------------------------------------------------- 1 | # Distribution / packaging 2 | .Python 3 | env/ 4 | build/ 5 | develop-eggs/ 6 | dist/ 7 | downloads/ 8 | eggs/ 9 | .eggs/ 10 | lib/ 11 | lib64/ 12 | parts/ 13 | sdist/ 14 | var/ 15 | *.egg-info/ 16 | .installed.cfg 17 | *.egg 18 | 19 | # Serverless directories 20 | .serverless 21 | layer 22 | -------------------------------------------------------------------------------- /3.6/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:build-python3.6 2 | 3 | RUN pip install -t /opt/python/ psycopg2-binary 4 | 5 | WORKDIR /var/task 6 | -------------------------------------------------------------------------------- /3.6/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | set -e 4 | 5 | rm -rf layer 6 | docker build -t psycopg2-lambda-layer . 7 | CONTAINER=$(docker run -d psycopg2-lambda-layer false) 8 | docker cp $CONTAINER:/opt layer 9 | docker rm $CONTAINER 10 | touch layer/.slsignore 11 | cat > layer/.slsignore << EOF 12 | **/*.a 13 | **/*.la 14 | share/** 15 | include/** 16 | bin/** 17 | EOF 18 | -------------------------------------------------------------------------------- /3.6/serverless.yml: -------------------------------------------------------------------------------- 1 | service: psycopg2-lambda-layer 2 | 3 | provider: 4 | name: aws 5 | runtime: python3.6 6 | profile: jb 7 | 8 | # you can overwrite defaults here 9 | # stage: dev 10 | region: eu-central-1 11 | 12 | layers: 13 | psycopg2-py36: 14 | description: "psycopg2 python postgresql client library." 15 | buildScript: ./build.sh 16 | path: layer 17 | compatibleRuntimes: 18 | - python3.6 19 | allowedAccounts: 20 | - '*' 21 | retain: true 22 | -------------------------------------------------------------------------------- /3.6/setup.cfg: -------------------------------------------------------------------------------- 1 | [build_ext] 2 | define= 3 | 4 | # PSYCOPG_DISPLAY_SIZE enable display size calculation (a little slower) 5 | # HAVE_PQFREEMEM should be defined on PostgreSQL >= 7.4 6 | # PSYCOPG_DEBUG can be added to enable verbose debug information 7 | 8 | # "pg_config" is required to locate PostgreSQL headers and libraries needed to 9 | # build psycopg2. If pg_config is not in the path or is installed under a 10 | # different name uncomment the following option and set it to the pg_config 11 | # full path. 12 | #pg_config= 13 | 14 | # Set to 1 to use Python datetime objects for default date/time representation. 15 | use_pydatetime=1 16 | 17 | # If the build system does not find the mx.DateTime headers, try 18 | # uncommenting the following line and setting its value to the right path. 19 | #mx_include_dir= 20 | 21 | # For Windows only: 22 | # Set to 1 if the PostgreSQL library was built with OpenSSL. 23 | # Required to link in OpenSSL libraries and dependencies. 24 | have_ssl=0 25 | 26 | # Statically link against the postgresql client library. 27 | static_libpq=1 28 | 29 | # Add here eventual extra libraries required to link the module. 30 | #libraries= 31 | -------------------------------------------------------------------------------- /3.7/.gitignore: -------------------------------------------------------------------------------- 1 | # Distribution / packaging 2 | .Python 3 | env/ 4 | build/ 5 | develop-eggs/ 6 | dist/ 7 | downloads/ 8 | eggs/ 9 | .eggs/ 10 | lib/ 11 | lib64/ 12 | parts/ 13 | sdist/ 14 | var/ 15 | *.egg-info/ 16 | .installed.cfg 17 | *.egg 18 | 19 | # Serverless directories 20 | .serverless 21 | layer 22 | -------------------------------------------------------------------------------- /3.7/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:build-python3.7 2 | 3 | RUN pip install -t /opt/python/ psycopg2-binary 4 | 5 | WORKDIR /var/task -------------------------------------------------------------------------------- /3.7/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | set -e 4 | 5 | rm -rf layer 6 | docker build -t psycopg2-lambda-layer . 7 | CONTAINER=$(docker run -d psycopg2-lambda-layer false) 8 | docker cp $CONTAINER:/opt layer 9 | docker rm $CONTAINER 10 | touch layer/.slsignore 11 | cat > layer/.slsignore << EOF 12 | **/*.a 13 | **/*.la 14 | share/** 15 | include/** 16 | bin/** 17 | EOF 18 | -------------------------------------------------------------------------------- /3.7/serverless.yml: -------------------------------------------------------------------------------- 1 | service: psycopg2-lambda-layer 2 | 3 | provider: 4 | name: aws 5 | runtime: python3.7 6 | region: eu-central-1 7 | profile: jb 8 | 9 | layers: 10 | psycopg2-py37: 11 | description: "psycopg2 python postgresql client library." 12 | buildScript: ./build.sh 13 | path: layer 14 | compatibleRuntimes: 15 | - python3.7 16 | allowedAccounts: 17 | - '*' 18 | retain: true 19 | -------------------------------------------------------------------------------- /3.7/setup.cfg: -------------------------------------------------------------------------------- 1 | [build_ext] 2 | define= 3 | 4 | # PSYCOPG_DISPLAY_SIZE enable display size calculation (a little slower) 5 | # HAVE_PQFREEMEM should be defined on PostgreSQL >= 7.4 6 | # PSYCOPG_DEBUG can be added to enable verbose debug information 7 | 8 | # "pg_config" is required to locate PostgreSQL headers and libraries needed to 9 | # build psycopg2. If pg_config is not in the path or is installed under a 10 | # different name uncomment the following option and set it to the pg_config 11 | # full path. 12 | #pg_config= 13 | 14 | # Set to 1 to use Python datetime objects for default date/time representation. 15 | use_pydatetime=1 16 | 17 | # If the build system does not find the mx.DateTime headers, try 18 | # uncommenting the following line and setting its value to the right path. 19 | #mx_include_dir= 20 | 21 | # For Windows only: 22 | # Set to 1 if the PostgreSQL library was built with OpenSSL. 23 | # Required to link in OpenSSL libraries and dependencies. 24 | have_ssl=0 25 | 26 | # Statically link against the postgresql client library. 27 | static_libpq=1 28 | 29 | # Add here eventual extra libraries required to link the module. 30 | #libraries= 31 | -------------------------------------------------------------------------------- /3.8/.gitignore: -------------------------------------------------------------------------------- 1 | # Distribution / packaging 2 | .Python 3 | env/ 4 | build/ 5 | develop-eggs/ 6 | dist/ 7 | downloads/ 8 | eggs/ 9 | .eggs/ 10 | lib/ 11 | lib64/ 12 | parts/ 13 | sdist/ 14 | var/ 15 | *.egg-info/ 16 | .installed.cfg 17 | *.egg 18 | 19 | # Serverless directories 20 | .serverless 21 | layer 22 | -------------------------------------------------------------------------------- /3.8/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:build-python3.8 2 | 3 | RUN pip install -t /opt/python/ psycopg2-binary 4 | 5 | WORKDIR /var/task 6 | -------------------------------------------------------------------------------- /3.8/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | set -e 4 | 5 | rm -rf layer 6 | docker build -t psycopg2-lambda-layer . 7 | CONTAINER=$(docker run -d psycopg2-lambda-layer false) 8 | docker cp $CONTAINER:/opt layer 9 | docker rm $CONTAINER 10 | touch layer/.slsignore 11 | cat > layer/.slsignore << EOF 12 | **/*.a 13 | **/*.la 14 | share/** 15 | include/** 16 | bin/** 17 | EOF 18 | -------------------------------------------------------------------------------- /3.8/serverless.yml: -------------------------------------------------------------------------------- 1 | service: psycopg2-lambda-layer 2 | 3 | provider: 4 | name: aws 5 | runtime: python3.8 6 | region: eu-central-1 7 | profile: jb 8 | stage: prod 9 | 10 | layers: 11 | psycopg2-py38: 12 | description: "psycopg2 python postgresql client library." 13 | buildScript: ./build.sh 14 | path: layer 15 | compatibleRuntimes: 16 | - python3.8 17 | allowedAccounts: 18 | - '*' 19 | retain: true 20 | -------------------------------------------------------------------------------- /3.8/setup.cfg: -------------------------------------------------------------------------------- 1 | [build_ext] 2 | define= 3 | 4 | # PSYCOPG_DISPLAY_SIZE enable display size calculation (a little slower) 5 | # HAVE_PQFREEMEM should be defined on PostgreSQL >= 7.4 6 | # PSYCOPG_DEBUG can be added to enable verbose debug information 7 | 8 | # "pg_config" is required to locate PostgreSQL headers and libraries needed to 9 | # build psycopg2. If pg_config is not in the path or is installed under a 10 | # different name uncomment the following option and set it to the pg_config 11 | # full path. 12 | #pg_config= 13 | 14 | # Set to 1 to use Python datetime objects for default date/time representation. 15 | use_pydatetime=1 16 | 17 | # If the build system does not find the mx.DateTime headers, try 18 | # uncommenting the following line and setting its value to the right path. 19 | #mx_include_dir= 20 | 21 | # For Windows only: 22 | # Set to 1 if the PostgreSQL library was built with OpenSSL. 23 | # Required to link in OpenSSL libraries and dependencies. 24 | have_ssl=0 25 | 26 | # Statically link against the postgresql client library. 27 | static_libpq=1 28 | 29 | # Add here eventual extra libraries required to link the module. 30 | #libraries= 31 | -------------------------------------------------------------------------------- /3.9/.gitignore: -------------------------------------------------------------------------------- 1 | # Distribution / packaging 2 | .Python 3 | env/ 4 | build/ 5 | develop-eggs/ 6 | dist/ 7 | downloads/ 8 | eggs/ 9 | .eggs/ 10 | lib/ 11 | lib64/ 12 | parts/ 13 | sdist/ 14 | var/ 15 | *.egg-info/ 16 | .installed.cfg 17 | *.egg 18 | 19 | # Serverless directories 20 | .serverless 21 | layer 22 | -------------------------------------------------------------------------------- /3.9/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM public.ecr.aws/lambda/python:3.9 2 | 3 | RUN pip install -t /opt/python/ psycopg2-binary 4 | 5 | WORKDIR /var/task 6 | -------------------------------------------------------------------------------- /3.9/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | set -e 4 | 5 | rm -rf layer 6 | docker build -t psycopg2-lambda-layer . 7 | CONTAINER=$(docker run -d psycopg2-lambda-layer false) 8 | docker cp $CONTAINER:/opt layer 9 | docker rm $CONTAINER 10 | touch layer/.slsignore 11 | cat > layer/.slsignore << EOF 12 | **/*.a 13 | **/*.la 14 | share/** 15 | include/** 16 | bin/** 17 | EOF 18 | -------------------------------------------------------------------------------- /3.9/deploy.sh: -------------------------------------------------------------------------------- 1 | for region in "us-east-1" "us-east-2" "us-west-1" "us-west-2" "af-south-1" "ap-east-1" "ap-south-1" "ap-northeast-1" "ap-northeast-2" "ap-northeast-3" "ap-southeast-1" "ap-southeast-2" "ap-southeast-3" "ca-central-1" "eu-west-1" "eu-west-2" "eu-west-3" "eu-central-1" "eu-south-1" "me-south-1" "sa-east-1"; do 2 | sls deploy --region $region 3 | done 4 | -------------------------------------------------------------------------------- /3.9/serverless.yml: -------------------------------------------------------------------------------- 1 | service: psycopg2-lambda-layer 2 | 3 | provider: 4 | name: aws 5 | runtime: python3.9 6 | region: eu-central-1 7 | profile: jb 8 | stage: prod 9 | 10 | layers: 11 | psycopg2-py39: 12 | description: "psycopg2 python postgresql client library." 13 | buildScript: ./build.sh 14 | path: layer 15 | compatibleRuntimes: 16 | - python3.9 17 | allowedAccounts: 18 | - '*' 19 | retain: true 20 | -------------------------------------------------------------------------------- /3.9/setup.cfg: -------------------------------------------------------------------------------- 1 | [build_ext] 2 | define= 3 | 4 | # PSYCOPG_DISPLAY_SIZE enable display size calculation (a little slower) 5 | # HAVE_PQFREEMEM should be defined on PostgreSQL >= 7.4 6 | # PSYCOPG_DEBUG can be added to enable verbose debug information 7 | 8 | # "pg_config" is required to locate PostgreSQL headers and libraries needed to 9 | # build psycopg2. If pg_config is not in the path or is installed under a 10 | # different name uncomment the following option and set it to the pg_config 11 | # full path. 12 | #pg_config= 13 | 14 | # Set to 1 to use Python datetime objects for default date/time representation. 15 | use_pydatetime=1 16 | 17 | # If the build system does not find the mx.DateTime headers, try 18 | # uncommenting the following line and setting its value to the right path. 19 | #mx_include_dir= 20 | 21 | # For Windows only: 22 | # Set to 1 if the PostgreSQL library was built with OpenSSL. 23 | # Required to link in OpenSSL libraries and dependencies. 24 | have_ssl=0 25 | 26 | # Statically link against the postgresql client library. 27 | static_libpq=1 28 | 29 | # Add here eventual extra libraries required to link the module. 30 | #libraries= 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # psycopg2-lambda-layer 2 | AWS Lambda layer for psycopg2 3 | 4 | 5 | To use in your serverless.yml: 6 | ``` 7 | functions: 8 | hello: 9 | handler: handler.hello 10 | layers: 11 | # py 3.6: 12 | - arn:aws:lambda:us-east-1:898466741470:layer:psycopg2-py36:3 13 | - arn:aws:lambda:us-east-2:898466741470:layer:psycopg2-py36:1 14 | - arn:aws:lambda:us-west-2:898466741470:layer:psycopg2-py36:1 15 | - arn:aws:lambda:eu-central-1:898466741470:layer:psycopg2-py36:2 16 | - arn:aws:lambda:sa-east-1:898466741470:layer:psycopg2-py36:1 17 | # py 3.7: 18 | - arn:aws:lambda:eu-central-1:898466741470:layer:psycopg2-py37:6 19 | - arn:aws:lambda:ap-southeast-1:898466741470:layer:psycopg2-py37:1 20 | - arn:aws:lambda:us-east-1:898466741470:layer:psycopg2-py37:3 21 | - arn:aws:lambda:us-east-2:898466741470:layer:psycopg2-py37:1 22 | - arn:aws:lambda:us-west-2:898466741470:layer:psycopg2-py37:7 23 | - arn:aws:lambda:eu-west-1:898466741470:layer:psycopg2-py37:1 24 | - arn:aws:lambda:eu-west-2:898466741470:layer:psycopg2-py37:1 25 | - arn:aws:lambda:eu-west-3:898466741470:layer:psycopg2-py37:1 26 | - arn:aws:lambda:sa-east-1:898466741470:layer:psycopg2-py37:1 27 | - arn:aws:lambda:ap-southeast-1:898466741470:layer:psycopg2-py37:5 28 | - arn:aws:lambda:ap-southeast-2:898466741470:layer:psycopg2-py37:1 29 | - arn:aws:lambda:ca-central-1:898466741470:layer:psycopg2-py37:1 30 | - arn:aws:lambda:ap-south-1:898466741470:layer:psycopg2-py37:1 31 | # py 3.8: 32 | - arn:aws:lambda:ca-central-1:898466741470:layer:psycopg2-py38:1 33 | - arn:aws:lambda:us-east-1:898466741470:layer:psycopg2-py38:2 34 | - arn:aws:lambda:us-east-2:898466741470:layer:psycopg2-py38:1 35 | - arn:aws:lambda:us-west-1:898466741470:layer:psycopg2-py38:1 36 | - arn:aws:lambda:us-west-2:898466741470:layer:psycopg2-py38:1 37 | - arn:aws:lambda:eu-west-1:898466741470:layer:psycopg2-py38:1 38 | - arn:aws:lambda:eu-west-2:898466741470:layer:psycopg2-py38:1 39 | - arn:aws:lambda:eu-west-3:898466741470:layer:psycopg2-py38:1 40 | - arn:aws:lambda:eu-central-1:898466741470:layer:psycopg2-py38:1 41 | - arn:aws:lambda:eu-south-1:898466741470:layer:psycopg2-py38:1 42 | - arn:aws:lambda:ap-northeast-1:898466741470:layer:psycopg2-py38:1 43 | - arn:aws:lambda:ap-southeast-1:898466741470:layer:psycopg2-py38:1 44 | - arn:aws:lambda:ap-southeast-2:898466741470:layer:psycopg2-py38:1 45 | - arn:aws:lambda:sa-east-1:898466741470:layer:psycopg2-py38:1 46 | # py 3.9: 47 | - arn:aws:lambda:us-east-1:898466741470:layer:psycopg2-py39:1 48 | - arn:aws:lambda:us-east-2:898466741470:layer:psycopg2-py39:1 49 | - arn:aws:lambda:us-west-1:898466741470:layer:psycopg2-py39:1 50 | - arn:aws:lambda:us-west-2:898466741470:layer:psycopg2-py39:1 51 | - arn:aws:lambda:ca-central-1:898466741470:layer:psycopg2-py39:1 52 | - arn:aws:lambda:eu-west-1:898466741470:layer:psycopg2-py39:1 53 | - arn:aws:lambda:eu-west-2:898466741470:layer:psycopg2-py39:1 54 | - arn:aws:lambda:eu-west-3:898466741470:layer:psycopg2-py39:1 55 | - arn:aws:lambda:eu-central-1:898466741470:layer:psycopg2-py39:1 56 | ``` 57 | 58 | ## Regions 59 | Please use the layer that matches your region, or you will get a permissions error. 60 | 61 | ## No longer maintained 62 | 63 | It turns out that providing public lambda layers is too unpleasant and buggy, so I recommend building your own layer and using it instead of publicly-provided layers. 64 | 65 | Maybe AWS will make managing public layers less painful some day. 66 | --------------------------------------------------------------------------------