filmov
tv
Python Sql Server connection with AWS Lambda

Показать описание
The connection requires the SQL server drivers and unixobdc drivers to create a connection. However these must be compiled for the platform they will be deployed on and are not included in AWS Lambda instances by default.
#Fire up an EC2 instance and connect to it with ssh using your key file
ssh -i {path to your key file} ec2-user@{your server address}
Sudo yum install docker
sudo service docker start
sudo docker run -it --rm --entrypoint bash -e ODBCINI=/var/task -e ODBCSYSINI=/var/task -v "$PWD":/var/task lambci/lambda:build-python3.6
# Then, download ODBC source code, compile and take the output
cd unixODBC-2.3.5
./configure --sysconfdir=/var/task --disable-gui --disable-drivers --enable-iconv --with-iconv-char-enc=UTF8 --with-iconv-ucode-enc=UTF16LE --prefix=/home
make install
cd ..
mv /home/* .
# Install MSsql odbc driver
### IMPORTANT ####
# youtube doesnt allow angle brackets in descriptions
# replace % with right angle backet
ACCEPT_EULA=Y yum -y install msodbcsql
export CFLAGS="-I/var/task/include"
export LDFLAGS="-L/var/task/lib"
pip install pyodbc -t .
cp -r /opt/microsoft/msodbcsql .
### IMPORTANT ####
# youtube doesnt allow angle brackets in descriptions
# replace $ with left angle bracket
# replace % with right angle backet
[ODBC Driver 13 for SQL Server]
Description=Microsoft ODBC Driver 13 for SQL Server
UsageCount=1
EOF
[ODBC Driver 13 for SQL Server]
Driver = ODBC Driver 13 for SQL Server
Description = My ODBC Driver 13 for SQL Server
Trace = No
EOF
# Test if it works
cd ..
#start new terminal
sudo docker ps -a
#Thanks to Carloches for the orginial version of these instructions
#Fire up an EC2 instance and connect to it with ssh using your key file
ssh -i {path to your key file} ec2-user@{your server address}
Sudo yum install docker
sudo service docker start
sudo docker run -it --rm --entrypoint bash -e ODBCINI=/var/task -e ODBCSYSINI=/var/task -v "$PWD":/var/task lambci/lambda:build-python3.6
# Then, download ODBC source code, compile and take the output
cd unixODBC-2.3.5
./configure --sysconfdir=/var/task --disable-gui --disable-drivers --enable-iconv --with-iconv-char-enc=UTF8 --with-iconv-ucode-enc=UTF16LE --prefix=/home
make install
cd ..
mv /home/* .
# Install MSsql odbc driver
### IMPORTANT ####
# youtube doesnt allow angle brackets in descriptions
# replace % with right angle backet
ACCEPT_EULA=Y yum -y install msodbcsql
export CFLAGS="-I/var/task/include"
export LDFLAGS="-L/var/task/lib"
pip install pyodbc -t .
cp -r /opt/microsoft/msodbcsql .
### IMPORTANT ####
# youtube doesnt allow angle brackets in descriptions
# replace $ with left angle bracket
# replace % with right angle backet
[ODBC Driver 13 for SQL Server]
Description=Microsoft ODBC Driver 13 for SQL Server
UsageCount=1
EOF
[ODBC Driver 13 for SQL Server]
Driver = ODBC Driver 13 for SQL Server
Description = My ODBC Driver 13 for SQL Server
Trace = No
EOF
# Test if it works
cd ..
#start new terminal
sudo docker ps -a
#Thanks to Carloches for the orginial version of these instructions
Комментарии