Skip to content

Instantly share code, notes, and snippets.

@lorne-luo
Created July 21, 2020 07:14
Show Gist options
  • Save lorne-luo/8ef6a3469c93d6db9f88badf8a3f942a to your computer and use it in GitHub Desktop.
Save lorne-luo/8ef6a3469c93d6db9f88badf8a3f942a to your computer and use it in GitHub Desktop.
build pyodbc lambda layer
docker run -it --rm --entrypoint bash -e ODBCINI=/opt/odbc.ini -e ODBCSYSINI=/opt/ -v "$PWD":/opt lambci/lambda:build-python3.8
# install unixODBC
curl ftp://ftp.unixodbc.org/pub/unixODBC/unixODBC-2.3.7.tar.gz -O
tar xzvf unixODBC-2.3.7.tar.gz
cd unixODBC-2.3.7
./configure --sysconfdir=/opt --disable-gui --disable-drivers --enable-iconv --with-iconv-char-enc=UTF8 --with-iconv-ucode-enc=UTF16LE --prefix=/opt
make
make install
cd ..
mv unixODBC-2.3.7 unixODBC-2.3.7.tar.gz /tmp
# install msodbcsql17
curl https://packages.microsoft.com/config/rhel/6/prod.repo > /etc/yum.repos.d/mssql-release.repo
yum install e2fsprogs.x86_64 0:1.43.5-2.43.amzn1 fuse-libs.x86_64 0:2.9.4-1.18.amzn1 libss.x86_64 0:1.43.5-2.43.amzn1 openssl
ACCEPT_EULA=Y yum install msodbcsql17 --disablerepo=amzn*
export CFLAGS="-I/opt/include"
export LDFLAGS="-L/opt/lib"
cd /opt
cp -r /opt/microsoft/msodbcsql17/ .
mv /opt/microsoft/ /tmp
# install pyodbc
mkdir /opt/python/
cd /opt/python/
pip install pyodbc -t .
# create odbcinst.ini and odbc.ini
cd /opt
cat <<EOF > odbcinst.ini
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/msodbcsql17/lib64/libmsodbcsql-17.3.so.1.1
UsageCount=1
EOF
cat <<EOF > odbc.ini
[ODBC Driver 17 for SQL Server]
Driver = ODBC Driver 17 for SQL Server
Description = My ODBC Driver 17 for SQL Server
Trace = No
EOF
# create zip, upload this zip to lambda layer
cd /opt
zip -r9 ~/pyodbc-layer.zip .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment