I'm trying to create an AWS Lambda function in Python to connect to an Oracle Database (for now, just a test connection). But I'm not got success to complete the flow. Every time I see this error message:
{ "errorMessage": "Unable to import module 'lambda_function': No module named 'cx_Oracle'", "errorType": "Runtime.ImportModuleError" }
I've created a virtualenv at Ubuntu WSL, install the Oracle InstantClient on the lib folder, install cx_oracle by pip at sites-package folder, and create my lambda function at the same folder, zip everything, upload at my S3 and put to run.
Can anyone help me?
My code:
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 lambda_handler(event, context):
return str(
cx_Oracle.connect(
'username',
'password',
cx_Oracle.makedsn(
'rds.amazonaws.com', 1521, 'SOME_SID',
)
).cursor().execute('SELECT 42 FROM DUAL').fetchone()
)
My sites-package folder:
** My lambda config: **
AWS Lambda runs with Amazon Linux, so you need the compatible library of cx_Oracle, in this case manylinux.whl
just download the whl, unzip it, and copy the .so file into your lib folder.
That way Lambda will recognize cx_Oracle.
The folder structure should look like this: structure
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.