Home > other >  Library error on docker container (AWS Lambda)
Library error on docker container (AWS Lambda)

Time:09-17

I'm looking to execute a python script on AWS Lambda using a Docker container loaded on AWS ECR. I've managed to create a docker container starting from the amazon image they recommend using for a python script. This is the Dockerfile:


# Copy function code
COPY app.py ${LAMBDA_TASK_ROOT}
COPY config.py ${LAMBDA_TASK_ROOT}
COPY abort_occurrance.txt ${LAMBDA_TASK_ROOT}
COPY actions_logging.txt ${LAMBDA_TASK_ROOT}
COPY execution_log.txt ${LAMBDA_TASK_ROOT}
COPY warning_job_occurrance.txt ${LAMBDA_TASK_ROOT}

# Install the function's dependencies using file requirements.txt
# from your project folder.

COPY requirements.txt  .
RUN  pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"

CMD ["app.py"]
ENTRYPOINT ["python3"] 

As seen here, app.py is my script that has to run on container start. Once created the image, i can easily start my container on local machine, but when i load it on AWS ECR and link it to AWS Lambda it won't work. This is the error that is returned on CloudWatch:

Traceback (most recent call last):
File "app.py", line 2, in <module>
from exchangelib import Credentials, Account
File "/var/task/exchangelib/__init__.py", line 3, in <module>
from .account import Account, Identity
File "/var/task/exchangelib/account.py", line 12, in <module>
from .folders import Folder, AdminAuditLogs, ArchiveDeletedItems, ArchiveInbox, ArchiveMsgFolderRoot, \
File "/var/task/exchangelib/folders/__init__.py", line 16, in <module>
from .roots import Root, ArchiveRoot, PublicFoldersRoot, RootOfHierarchy
File "/var/task/exchangelib/folders/roots.py", line 17, in <module>
class RootOfHierarchy(BaseFolder, metaclass=EWSMeta):
File "/var/task/exchangelib/folders/roots.py", line 26, in RootOfHierarchy
_subfolders_lock = 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(
OSError: [Errno 38] Function not implemented
START RequestId: f8056c6e-9ca4-4aba-a1aa-191dca52ea35 Version: $LATEST
END RequestId: f8056c6e-9ca4-4aba-a1aa-191dca52ea35
REPORT RequestId: f8056c6e-9ca4-4aba-a1aa-191dca52ea35  Duration: 3003.57 ms    Billed Duration: 3000 ms    Memory Size: 128 MB Max Memory Used: 22 MB  
2021-09-15T12:52:25.585Z f8056c6e-9ca4-4aba-a1aa-191dca52ea35 Task timed out after 3.00 seconds

How is it possible that a container works on local docker but when i test it on lambda it does not work?

Thank you

CodePudding user response:

Lambda does not support parallel processing for all runtimes. This could be why it's working local but not in lambda.

https://aws.amazon.com/blogs/compute/parallel-processing-in-python-with-aws-lambda/

  • Related