Connecting AWS Python Lambda to an Oracle Database, replacing cx_Oracle with python-oracledb

If you would like to connect an AWS python lambda to an Oracle database, there is a new package called python-oracledb which replaces the old package cx_Oracle. A search will reveal the old cx_Oracle package is difficult to install, with many work arounds and hacks - due to operating system library requirements.

A new package python-oracledb was released in May of 2022, and simplifies the installation process.
python-oracledb can run in Thin mode (the default), with an optional Thick mode requiring additional client dependencies.

More information on Thin vs Thick and upgrading from the cx_Oracle package, can be found on the python-oracledb website.
A feature comparison of python-oracledb Thin vs Thick vs cx_Oracle is also available.

Its worth noting that references to the package as python-oracledb and oracledb are used interchangeably.
The former, typically being used in documentation to distinguish it from other languages.

Installtion Trouble shooting

Error “cannot import name ‘base_impl’”

If you receive the error below, its worth checking that your package installation is correct:

   "errorMessage": "Unable to import module 'main': cannot import name 'base_impl' from partially initialized module 'oracledb'
    (most likely due to a circular import) (/var/task/oracledb/",
   "errorType": "Runtime.ImportModuleError",

Remember that packaging is platform dependant and ensure your build process hasn’t excluded any files.

Error “DPY-6000: cannot connect to database”

I received the following error, as the Oracle database I was trying to connect to required some encryption settings:

DPY-6000: cannot connect to database. Listener refused connection. (Similar to ORA-12660)

The error ORA-12660 indicates some Encryption settings in sqlnet.ora need to be set.
sqlnet.ora settings can only be done in Thick mode with the python-oracledb package.
See the Oracle python-oracledb documentation on the sqlnet.ora, on how this can be set.

python-oracledb - docs
python-oracledb - github
Open Source Python Thin Driver for Oracle Database
ORA-12660: Encryption Or Crypto-checksumming Parameters Incompatible When Connecting To Application