TheJumpCloud / jcapi-python

21 stars 20 forks source link

Issues when using jcapiv1.SystemusersApi(jcapiv1.ApiClient(configuration)) on AWS Lambda #50

Open maneskiivan opened 3 years ago

maneskiivan commented 3 years ago

Hello,

I am able to use the script below successfully when deployed locally on my computer:

`configuration = jcapiv1.Configuration() configuration.api_key['x-api-key'] = jumpcloud_apikey

create an instance of the API class

api_instance = jcapiv1.SystemusersApi(jcapiv1.ApiClient(configuration))
content_type = 'application/json'  # str |  (default to application/json)
accept = 'application/json'  # str |  (default to application/json)
x_org_id = jumpcloud_org_id  # str |  (optional) (default to )
body = jcapiv1.Systemuserputpost(
  email='jdoe@email.com',
  username='jdoe',
  firstname='John',
  lastname='Doe'
)

api_response = api_instance.systemusers_post(content_type, accept, body=body, x_org_id=x_org_id)`

When I use the script on AWS Lambda I get the following error:

{ "errorMessage": "[Errno 38] Function not implemented", "errorType": "OSError", "stackTrace": [ " File \"/var/task/lambda_function.py\", line 17, in lambda_handler\n api_instance = jcapiv1.SystemusersApi(jcapiv1.ApiClient(configuration))\n", " File \"/opt/python/lib/python3.8/site-packages/jcapiv1/api_client.py\", line 69, in init\n self.pool = ThreadPool()\n", " File \"/var/lang/lib/python3.8/multiprocessing/pool.py\", line 925, in init\n Pool.init(self, processes, initializer, initargs)\n", " File \"/var/lang/lib/python3.8/multiprocessing/pool.py\", line 196, in init\n self._change_notifier = self._ctx.SimpleQueue()\n", " File \"/var/lang/lib/python3.8/multiprocessing/context.py\", line 113, in SimpleQueue\n return SimpleQueue(ctx=self.get_context())\n", " File \"/var/lang/lib/python3.8/multiprocessing/queues.py\", line 336, in init\n self._rlock = ctx.Lock()\n", " File \"/var/lang/lib/python3.8/multiprocessing/context.py\", line 68, in Lock\n return Lock(ctx=self.get_context())\n", " File \"/var/lang/lib/python3.8/multiprocessing/synchronize.py\", line 162, in init\n SemLock.init(self, SEMAPHORE, 1, 1, ctx=ctx)\n", " File \"/var/lang/lib/python3.8/multiprocessing/synchronize.py\", line 57, in init\n sl = self._semlock = _multiprocessing.SemLock(\n" ] }

I found some article that suggest I should use the multiprocessing library to handle this issue. I tried resolving this with that library with no success.

Any help would be greatly appreciated.

Thank you.

maneskiivan commented 3 years ago

I forked the library and removed the multiprocessing parts all together. That resolved the issue.

chad-larsen-rapid commented 1 year ago

@maneskiivan, do you recall which parts you removed from your fork? I'm running into the same issue and hoping to follow your steps.

maneskiivan commented 1 year ago

@chad-larsen-rapid , You have to remove lines in this file: https://github.com/TheJumpCloud/jcapi-python/blob/master/jcapiv1/jcapiv1/api_client.py If you are using v2 do the same there. Lines to remove: 17 from multiprocessing.pool import ThreadPool 69 self.pool = ThreadPool() 78 - 80 def del(self): self.pool.close() self.pool.join()