Lambda, Python, and Oracle

This document describes the bare minimum you’ll need to use cx_oracle on a Lambda. Works for both Pythons 2 and 3. This is a bare Lambda and has nothing to do with Zappa or Chalice or Serverless or anything else all the cool kids seem to be using these days.

Shared Objects

Go here and download That’s all you’ll need. Extract it. Then copy these files to a separate folder called “lib”.

Then, you’ll have to install libaio on your system and copy into “lib”.

But I’m Lazy

OK. I’ve cached all that here.

App Structure

└── lib


from __future__ import print_function
import cx_Oracle

# Yeah, you need this. 
with open('/tmp/HOSTALIASES', 'w') as f: f.write(f'{os.uname()[1]} localhost\n')

# Oracle away!
def handler(event, context):
    return str(
                '', 1521, 'SOME_SID',
        ).cursor().execute('SELECT 42 FROM DUAL').fetchone()

Now pip install cx_oracle -t my_lambda/ to install cx_oracle into that folder. Zip it up and make a Lambda with test.handler as the… handler.

Environment Variables

You’ll need to set these before you execute your Lambda

You’re all set!