{"id":23991755,"url":"https://github.com/jag-010/lambda-function-for-oracle-db","last_synced_at":"2025-09-13T15:52:34.515Z","repository":{"id":195885748,"uuid":"385956987","full_name":"JAG-010/lambda-function-for-oracle-db","owner":"JAG-010","description":"Lambda function to connect and query oracle RDS database","archived":false,"fork":false,"pushed_at":"2021-07-15T16:20:01.000Z","size":166,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-21T17:39:09.829Z","etag":null,"topics":["aws-lambda","oracle-database","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JAG-010.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-07-14T13:49:33.000Z","updated_at":"2022-12-14T14:20:31.000Z","dependencies_parsed_at":"2023-09-20T01:00:54.403Z","dependency_job_id":null,"html_url":"https://github.com/JAG-010/lambda-function-for-oracle-db","commit_stats":null,"previous_names":["jag-010/lambda-function-for-oracle-db"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JAG-010/lambda-function-for-oracle-db","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JAG-010%2Flambda-function-for-oracle-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JAG-010%2Flambda-function-for-oracle-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JAG-010%2Flambda-function-for-oracle-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JAG-010%2Flambda-function-for-oracle-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JAG-010","download_url":"https://codeload.github.com/JAG-010/lambda-function-for-oracle-db/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JAG-010%2Flambda-function-for-oracle-db/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274988527,"owners_count":25386546,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-13T02:00:10.085Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-lambda","oracle-database","python"],"created_at":"2025-01-07T19:59:52.788Z","updated_at":"2025-09-13T15:52:34.469Z","avatar_url":"https://github.com/JAG-010.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AWS Lambda function for Oracle database\n\u003e Lambda function to connect and query oracle RDS database\n\nThis article will explain how to create a AWS Lambda function to connect to Oracle (RDS) database and query data. \n\nSince lambda is based on linux environment its recommended to create this function on linux host. If you are using windows machine make use to WSL or VM or Docker.\n\n**Prerequisites:**\n\n1. Python 3.8\n2. [cx_Oracle python module](https://pypi.org/project/cx-Oracle/#files)\n3. [Oracle instant client](https://www.oracle.com/in/database/technologies/instant-client/linux-x86-64-downloads.html)\n4. [libiao package](https://pkgs.org/download/libaio)\n\n👆 Download and keep it ready\n\n### **Step 1:** Check the python version installed \nAWS Lambda supports Python version 3.6/3.7/3.8 at the time of this article written.\n\n```shell\n$ python --version\nPython 3.8.11\n```\n\n### **Step 2:** Install pip\n\n```shell\n$ sudo apt install python3-pip\n\n$ pip3 --version\npip 21.1.3 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)\n```\n\n### **Step 3:** Install Virtual Python Environment builder\n\n```shell\n$ pip3 install virtualenv\nCollecting virtualenv\n  Downloading virtualenv-20.6.0-py2.py3-none-any.whl (5.3 MB)\n     |████████████████████████████████| 5.3 MB 2.5 MB/s\nCollecting distlib\u003c1,\u003e=0.3.1\n  Downloading distlib-0.3.2-py2.py3-none-any.whl (338 kB)\n     |████████████████████████████████| 338 kB 4.4 MB/s\nCollecting backports.entry-points-selectable\u003e=1.0.4\n  Downloading backports.entry_points_selectable-1.1.0-py2.py3-none-any.whl (6.2 kB)\nCollecting filelock\u003c4,\u003e=3.0.0\n  Downloading filelock-3.0.12-py3-none-any.whl (7.6 kB)\nCollecting platformdirs\u003c3,\u003e=2\n  Downloading platformdirs-2.0.2-py2.py3-none-any.whl (10 kB)\nCollecting six\u003c2,\u003e=1.9.0\n  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)\nInstalling collected packages: six, platformdirs, filelock, distlib, backports.entry-points-selectable, virtualenv\nSuccessfully installed backports.entry-points-selectable-1.1.0 distlib-0.3.2 filelock-3.0.12 platformdirs-2.0.2 six-1.16.0 virtualenv-20.6.0\nWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv      \n/ # \n```\n\n### **Step 4:** Create virtual environment `oralmdfn`\n```shell\n$ virtualenv oralmdfn\ncreated virtual environment CPython3.8.11.final.0-64 in 688ms\n  creator CPython3Posix(dest=/oralmdfn, clear=False, no_vcs_ignore=False, global=False)\n  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv)\n    added seed packages: pip==21.1.3, setuptools==57.1.0, wheel==0.36.2\n  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator\n```\n\n### **Step 5:** Activate virtual environment\n```sh\n$ source oralmdfn/bin/activate\n(oralmdfn) $ \n\n# you will see the virtual environment name in () if activated \n```\n\n### **Step 6:** Install cx_Oracle module vai pip\nMake sure you have downloaded the right version of cx_Oracle module. In this artical I use python 3.8 so i have downloaded `cx_Oracle-8.2.1-cp38-cp38-manylinux1_x86_64.whl` (👈cp38 is for python 3.8)\n\n```shell\n$ pip3 install cx_Oracle-8.2.1-cp38-cp38-manylinux1_x86_64.whl \nProcessing ./cx_Oracle-8.2.1-cp38-cp38-manylinux1_x86_64.whl\nInstalling collected packages: cx-Oracle\nSuccessfully installed cx-Oracle-8.2.1\n```\n\nverify cx-Oracle installation \n```shell\n$ ls  oralmdfn/lib/python3.8/site-packages/cx*\noralmdfn/lib/python3.8/site-packages/cx_Oracle.cpython-38-x86_64-linux-gnu.so\n\noralmdfn/lib/python3.8/site-packages/cx_Oracle-8.2.1.dist-info\n```\n\n### **Step 7:** Extract libiao rpm\n\nInstall rpm2cpio package on linux\n```shell\n$ apt-get install rpm2cpio\n\n$ apt-get install cpio # use this command to install cpio if not installed \n\n$ rpm2cpio lib64aio1-0.3.111-2pclos2020.x86_64.rpm | cpio -idmv\n./usr/lib64/libaio.so.1\n./usr/lib64/libaio.so.1.0.0\n./usr/lib64/libaio.so.1.0.1\n54 blocks\n```\n\ngo to `usr/lib64/` \n\n```shell\n$ ls -l $PWD/usr/lib64/\ntotal 32\nlrwxrwxrwx 1 root root    15 Jul 15 02:01 libaio.so.1 -\u003e libaio.so.1.0.1\n-rwxr-xr-x 1 root root 13536 Sep 22  2020 libaio.so.1.0.0\n-rwxr-xr-x 1 root root 13536 Sep 22  2020 libaio.so.1.0.1\n\n$ rm $PWD/usr/lib64/libaio.so.1   ## to remove the soft link \n$ cp $PWD/usr/lib64/libaio.so.1.0.1 $PWD/usr/lib64/libaio.so.1\n```\n\n### **Step 8:** Create lambda function zip file\n\ncreate a new directory \n```shell\n$ mkdir ora_lmd_fn_py38\n```\ncopy files and folders as mentioned below\n```shell\n$ cp -rp oralmdfn/lib/python3.8/site-packages/cx_Oracle* ora_lmd_fn_py38/\n$ cp -rp instantclient_18_5/* ora_lmd_fn_py38/\n$ cp usr/lib64/libaio.so.1 ora_lmd_fn_py38/\n```\n\nfinally copy this [python script](oralmdfn.py) to the folder\n```shell\n$ cp oralmdfn.py ora_lmd_fn_py38/\n\n$ ls ora_lmd_fn_py38/\nBASIC_LITE_LICENSE                        genezi                 libipc1.so       libociicus.so     ojdbc8.jar\nBASIC_LITE_README                         libaio.so.1            libmql1.so       libocijdbc18.so   oralmdfn.py\nadrci                                     libclntsh.so           libnnz18.so      libons.so         ucp.jar\ncx_Oracle-8.2.1.dist-info                 libclntsh.so.18.1      libocci.so       liboramysql18.so  uidrvci\ncx_Oracle.cpython-38-x86_64-linux-gnu.so  libclntshcore.so.18.1  libocci.so.18.1  network           xstreams.jar\n```\n\n### **Step 9:** Archive the `ora_lmd_fn_py38` folder with zip\n\n```shell\n$ cd ora_lmd_fn_py38/\n$ zip -r ora_lmd_fn_py38.zip *\n$ ls -lh *.zip\n-rw-r--r-- 1 root root 58M Jul 15 02:38 ora_lmd_fn_py38.zip\n```\n\nSince our zip file is more than 10MB we need to upload to S3 bucket to add it to Lambda\n\n### **Step 10:** \n\nFollowing steps to be performed on AWS management console\n\n**Step 10.1:**\nCreate S3 bucket and upload `ora_lmd_fn_py38.zip` file to it\n\n**Step 10.2:**\nCreate a lambda function \n![Create Lambda function](images/create-fn.png)\n\nEdit Handler as `oralmdfn.lambda_handler` (our python file name is `oralmdfn` and handler name is `lambda_handler`)\n![Edit handler](images/handler.png)\n\n**Step 10.3:** \nUpload zip file from S3 to Lambda\n\nGet zip file URI\n![zip file URI](images/s3.png)\n\nUpload zip file to Lambda\n![upload zip](images/upload-zip.png)\n\n**Step 10.4:**\nTest the code\n\nOn lambda page click Test button \n\nExecution result: succeeded 👍\n![Test code](images/test-code.png)\n\nsee Log output for query output\n\n###### Feel free to reach me if any issues or open a issue on GitHub\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjag-010%2Flambda-function-for-oracle-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjag-010%2Flambda-function-for-oracle-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjag-010%2Flambda-function-for-oracle-db/lists"}