pythonaws-lambdadeepsecurity

"[ERROR] OSError: [Errno 38] Function not implemented" - Accessing trend deepsecurity.ComputersApi via Lambda


I have written a python script that successfully queries the trend deepsecurity api calls when ran locally on my machine. I've been tasked with running the script in an aws lambda so that it is automated and can be scheduled.

The script is following the examples in the api reference and calls the legacy api successfully. However when I attempt to query using the computers api It blows up on the line : computers_api = deepsecurity.ComputersApi(deepsecurity.ApiClient(configuration))

def get_computer_status_api():
    # Include computer status information in the returned Computer objects
    #expand = deepsecurity.Expand(deepsecurity.Expand.computer_status)
    expand = deepsecurity.Expand()
    expand.add(deepsecurity.Expand.security_updates)
    expand.add(deepsecurity.Expand.computer_status)
    expand.add(deepsecurity.Expand.anti_malware)

    # Set Any Required Values
    computers_api = deepsecurity.ComputersApi(deepsecurity.ApiClient(configuration))

    try:
        computers = computers_api.list_computers(api_version, expand=expand.list(), overrides=False)
        print("Querying ComputersApi...")
        api_response_str=str(computers)
        computer_count = len(computers.computers)
        print(str(computer_count) + " Computers listed in Trend")
    ...

the error I get is :

[ERROR] OSError: [Errno 38] Function not implemented
Traceback (most recent call last):
  File "/var/task/handler.py", line 782, in main
    get_computer_status_api()
  File "/var/task/handler.py", line 307, in get_computer_status_api
    computers_api = deepsecurity.ComputersApi(deepsecurity.ApiClient(configuration))
  File "/var/task/deepsecurity/api_client.py", line 69, in __init__
    self.pool = ThreadPool()
  File "/var/lang/lib/python3.8/multiprocessing/pool.py", line 925, in __init__
    Pool.__init__(self, processes, initializer, initargs)
  File "/var/lang/lib/python3.8/multiprocessing/pool.py", line 196, in __init__
    self._change_notifier = self._ctx.SimpleQueue()
  File "/var/lang/lib/python3.8/multiprocessing/context.py", line 113, in SimpleQueue
    return SimpleQueue(ctx=self.get_context())
  File "/var/lang/lib/python3.8/multiprocessing/queues.py", line 336, in __init__
    self._rlock = ctx.Lock()
  File "/var/lang/lib/python3.8/multiprocessing/context.py", line 68, in Lock
    return Lock(ctx=self.get_context())
  File "/var/lang/lib/python3.8/multiprocessing/synchronize.py", line 162, in __init__
    SemLock.__init__(self, SEMAPHORE, 1, 1, ctx=ctx)
  File "/var/lang/lib/python3.8/multiprocessing/synchronize.py", line 57, in __init__
    sl = self._semlock = _multiprocessing.SemLock(

searching for this error it implies that I can't use the deepsecurity api in a lambda because lambdas don't support multiprocessing.

Looking for either confirmation that this is the case or suggestions for what I can change to get this working.

Trend support ticket suggested posting to here.


Solution

  • Resolved the issue by changing the python version from 3.8 to 3.7 in the lambda. The script now runs successfully