miércoles, 26 de enero de 2022

How to create a Lambda Layer for Oracle Database

 In this article I will show you how to create a Lambda layer for Python 3.9 to connect to an Oracle Database using "Oracle CX".

Firstable, we will need to download the Oracle Client Binaries, you can download it from the following link:

https://www.oracle.com/cis/database/technologies/instant-client/linux-x86-64-downloads.html

It's very important that you download the "Basic Light" version of the Oracle Client binaries, the reason is that this is the smallest version and we need to keep the layer as smaller as possible because AWS Lambda has a limitation in Space for libraries which is  50 MB (zipped, for direct upload)  and 250 MB (unzipped):

In this example I am downloading the Version 21.6.0.0.0 (Requires glibc 2.14), but you can use any version.

Since AWS Lamba is executed on Linux, we need to create the lawyer also in Linux, for this layer I was using RHL8.

Create a directory called "python" this is mandatory for AWS Layers:

mkdir -p python


Install Oracle cx:

pip3 install -r cx_Oracle -t python

unzip the oracle client binaries into the "python" directory: 

unzip /home/oracle/instantclient-basiclite-linux.x64-21.6.zip -d python

cd python/instantclient_21_6/

The structure of the oracle client binaries should be similar to the following:


Put attention to the library "libaio.so.1", if you don't have it, you have to copy it:

sudo yum install libaio -y
cp /lib64/libaio.so.1 python/instantclient_21_6/lib/libaio.so.1

 I have created an AWS Layer for Python 3.9 that I have been using so far with my Lambdas, In case you are looking for something ready to use, you can download mine from the following link.

Download Layer for AWS Lambda for Python 3.9:

https://drive.google.com/file/d/1MGL7XK1yC24AmVp4MxFDOGQMPuKU7xKN/view?usp=sharing

No hay comentarios:

Publicar un comentario

Oracle ACE Director Award - Deiby Gómez

Thanks #OracleACE Program for this awesome certificate recognizing the work I have done in the community for the last year. Looking forwa...