AWS Python Lambda with Oracle - OID Generation Failed

跟風遠走 提交于 2019-12-01 20:08:03

Ok, here is the explanation: Oracle has a funny behavior where if the hostname given by hostname can't be resolved, it will fail connecting to the DB. Fortunately, in Linux, one can override the DNS entry for a session by writing an alias file in /tmp, then setting the environment variable HOSTALIASES to that file.

So adding this code to my function help to generate this file, and now I can successfully connect:

f = open('/tmp/HOSTALIASES','w')
str_host = os.uname()[1]
f.write(str_host + ' localhost\n')
f.close()

Hope it can help someone else !

Anthony Tuininga

See the following other question for the resolution to this problem.

sqlplus remote connection giving ORA-21561

Effectively the client requires a host name in order to generate a unique identifier which is used when connecting to the database.

The accepted solution for this correct, but please also be aware that the HOSTALIASES mechanism does require working DNS (as strange as it sounds).

I struggled with this for a few hours having implemented the accepted solution and realised that I was not permitting outbound DNS on the security group attached to by Lambda function VPC interface (my connection was by IP address to Oracle DB, so initially did not think this was required).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!