This repository provides a framework for building AWS Lambda layers that enable connectivity to Microsoft SQL Server databases using the pyodbc library. Each artifact is version-specific, tailored for a particular combination of Python, Microsoft ODBC driver and UNIXODBC versions. The GitHub Actions CI/CD pipeline automates the building, packaging and deployment of these artifacts as zip files, allowing developers to easily create and utilize layers in their AWS Lambda functions.
Currently, this project supports only x86_64 architecture. Future updates will include support for arm64 architecture.
-
Version-Specific Artifacts: Lambda layers are built for specific combinations of:
- Python versions:
3.9,3.10,3.11,3.12,3.13(using pyenv) - Microsoft ODBC driver versions:
17,18(using Microsoft ODBC driver versions) - UNIXODBC versions:
2.3.14(with support for multiple ODBC versions)
- Python versions:
-
Automated CI/CD with GitHub Actions: The build, test and release pipeline is fully automated using GitHub Actions. This setup ensures the latest Lambda layer artifacts are built, tested, and made available for download whenever a new version is pushed or a pull request is created.
-
Effortless Lambda Integration: Developers can easily download the pre-built zip files and directly use them in their Lambda functions without having to build or configure the pyodbc setup manually.
- Download the Pre-built Zip: The zip files for the required Python version, ODBC driver version, and UNIXODBC version can be downloaded from the GitHub release section.
- Upload the Layer to AWS Lambda:
- Go to the AWS Lambda console.
- Create a new Lambda layer and upload the downloaded zip file.
- Add the Layer to Your Lambda Function: Once the layer is uploaded, you can add it to any Lambda function where pyodbc and Microsoft SQL Server connectivity are needed.
The GitHub Actions workflow build.yml builds the Docker image, testing the layer and packages the Lambda layers as zip using the following steps:
- Docker Build: The Docker image is built with the specified Python, Microsoft ODBC, and UNIXODBC versions. The pyodbc library is installed for each Python version.
- Artifacts Creation: Zip files are created for each combination of Python and ODBC versions. These are stored in the
/opt/artifacts/directory. - Testing: Each Lambda layer is tested against a live SQL Server instance running in Docker. The test framework ensures that the pyodbc library and ODBC driver are functioning correctly.
- Release: Upon pushing a version tag (e.g.,
v1.0.0), the workflow automatically creates a new GitHub release and includes the relevant zip files for easy download.
The workflow supports building layers for multiple versions using a matrix strategy, allowing for simultaneous builds of:
- MSODBC Version:
18,17 - UNIXODBC Version:
2.3.14
In the al2 build.yml and al2023 build.yml, Python versions can be modified under the build job by adjusting the --build-arg PYTHON_VERSIONS="3.12,3.11".
To build the Lambda layers locally, you can follow these steps:
-
Clone the repository.
-
Install Docker if you haven’t already.
-
Run the following command to build the image and create the Lambda layer artifacts:
- Build Docker Image using amazonlinux 2
docker build -f Dockerfile-al2\ --build-arg PYTHON_VERSIONS="3.12,3.11,3.10,3.9" \ --build-arg MSODBC_VERSION=18 \ --build-arg UNIXODBC_VERSION=2.3.14 \ -t pyodbc-lambda-layer:multi-python-al2 .
- Build Docker Image using amazonlinux 2023
docker build -f Dockerfile-al2023\ --build-arg PYTHON_VERSIONS="3.13" \ --build-arg MSODBC_VERSION=18 \ --build-arg UNIXODBC_VERSION=2.3.14 \ -t pyodbc-lambda-layer:multi-python-al2023 .
-
Extract the zip files from the Docker container:
CONTAINER_AL2_ID=$(docker create pyodbc-lambda-layer:multi-python-al2) CONTAINER_AL2023_ID=$(docker create pyodbc-lambda-layer:multi-python-al2023) docker cp $CONTAINER_AL2_ID:/opt/artifacts/. . docker cp $CONTAINER_AL2023_ID:/opt/artifacts/. . docker rm $CONTAINER_AL2_ID docker rm $CONTAINER_AL2023_ID
-
The zip files will be available in the current directory for you to use.
If you want to test the Lambda layers, simply push your code to the relevant branch feature\{branchname} in the repository. The CI pipeline will automatically handle building and testing the Lambda layers based on the configuration in the build.yml file.
- Current Support: The layers support the x86_64 architecture for Python
3.9,3.10,3.11,3.12,3.13with Microsoft ODBC Driver versions17and18, and UNIXODBC2.3.14. - Future Updates:
- ARM64 Support: In future releases, support for the arm64 architecture will be added, allowing for broader compatibility across different AWS Lambda runtime environments.
-
PyODBC: This project uses the
pyodbclibrary, which is maintained by the open-source community. More information can be found in the pyodbc GitHub repository. -
Microsoft ODBC Driver for SQL Server: The Microsoft ODBC Driver is developed and maintained by Microsoft. Refer to the Microsoft documentation for more information.
-
unixODBC: unixODBC is used to facilitate ODBC connections on Unix systems. See the official unixODBC documentation for more details.
This project is licensed under the MIT. Feel free to use, modify, and distribute this project under the terms of the license.
Contributions are welcome! If you have suggestions for improvements or encounter issues, feel free to open an issue or submit a pull request.
This project was developed by Vigneshwar Thiyagarajan. Special thanks to the open-source community for their contributions and support.