├── .gitignore ├── package.json ├── example ├── handler.py ├── .gitignore └── serverless.yml ├── serverless.yml ├── Dockerfile └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .serverless/ 2 | layer 3 | node_modules/ 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aws-lambda-layer", 3 | "description": "", 4 | "version": "0.1.0", 5 | "dependencies": {}, 6 | "devDependencies": {} 7 | } 8 | -------------------------------------------------------------------------------- /example/handler.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | 3 | def hello(event, context): 4 | con = sqlite3.connect(':memory:') 5 | cur = con.cursor() 6 | row = cur.execute("SELECT 'Hello from an in-memory SQLite DB!'").fetchone() 7 | con.close() 8 | 9 | return row[0] 10 | -------------------------------------------------------------------------------- /example/.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 -------------------------------------------------------------------------------- /example/serverless.yml: -------------------------------------------------------------------------------- 1 | service: sqlite-example 2 | #frameworkVersion: ">=1.34.0 <2.0.0" 3 | 4 | provider: 5 | name: aws 6 | runtime: python3.6 7 | 8 | functions: 9 | hello: 10 | handler: handler.hello 11 | layers: 12 | - arn:aws:lambda:us-west-2:377024778620:layer:sqlitePython36:2 13 | -------------------------------------------------------------------------------- /serverless.yml: -------------------------------------------------------------------------------- 1 | service: python-sqlite-layers 2 | frameworkVersion: ">=1.34.0 <2.0.0" 3 | 4 | provider: 5 | name: aws 6 | 7 | layers: 8 | sqlitePython36: 9 | path: layer 10 | description: A Layer to fix SQLite support in Python 3.6 Lambda functions 11 | compatibleRuntimes: 12 | - python3.6 13 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:build-python3.6 2 | 3 | ENV PYTHON_VERSION=3.6.1 4 | RUN yum install -y tar xz yum-utils make automake gcc gcc-c++ sqlite sqlite-devel 5 | RUN curl -O https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz 6 | RUN tar xf Python-${PYTHON_VERSION}.tar.xz 7 | RUN mkdir -p /var/task/python 8 | WORKDIR Python-${PYTHON_VERSION} 9 | RUN ./configure --prefix=/var/task/python 10 | RUN make -j9 11 | RUN make altinstall 12 | # set workdir back 13 | WORKDIR /var/task 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SQLite Python Lambda Layer 2 | Like many Python programmers, you've probably been disappointed when you tried to import `sqlite3` 3 | in a Python3.6 AWS Lambda only to find out it doesn't work. This project remedies that by providing 4 | a [Lambda Layer](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html) that contains the necessary compiled library 5 | (`_sqlite3.so`). 6 | 7 | ## How to use 8 | First you must clone the repo, build the file, and publish it to AWS: 9 | ```shell 10 | git clone git@github.com:dschep/sqlite-lambda-layer 11 | cd sqlite-lambda-layer 12 | ./build 13 | sls deploy 14 | ``` 15 | Then see [the docs](https://serverless.com/framework/docs/providers/aws/guide/functions/#layers) 16 | and configure your lambda to use the layer you just published. 17 | --------------------------------------------------------------------------------