1 year ago

#376212

test-img

Knut Hellan

Binary sometimes, but not always, fails in AWS Lambda

We are running LibreOffice to convert Office documents to PDF in AWS Lambda. This normally works well. However, sometimes it fails with a DeploymentException. If this happens, it fails for all invocations on a single Lambda host (meaning all invocations in a single log file)

This is the Dockerfile without our python code copying and CMD/entrypoint:

FROM public.ecr.aws/lambda/python:3.9

RUN yum install -y \
    cups-libs \
    cairo \
    libSM \
    jre \
    tar

RUN curl --location -o libreoffice.rpm.tar.gz https://download.documentfoundation.org/libreoffice/stable/7.2.5/rpm/x86_64/LibreOffice_7.2.5_Linux_x86-64_rpm.tar.gz
RUN tar zxf libreoffice.rpm.tar.gz
RUN yum install -y LibreOffice_7.2.5.2_Linux_x86-64_rpm/RPMS/*.rpm

COPY requirements.txt .
RUN pip install -r requirements.txt && rm requirements.txt

The Office file is copied to local tmp space handled by tempfile.TemporaryDirectory to ensure we don't leave anything behind to fill up when the Lambda is reused.

This is the subprocess execution:

    with tempfile.TemporaryDirectory(dir=work_directory) as work_directory_name:
        my_work_directory = Path(work_directory_name)
        tmp_filename = my_work_directory / original_filename.name
        with tmp_filename.open('wb') as tmp_file:
            tmp_file.write(data)
        result = subprocess.run(
            ['libreoffice7.2', '--headless', '--nologo', '--convert-to', 'pdf', '--outdir', my_work_directory, tmp_filename],
            env={
                'HOME': work_directory
            }
        )

When this fails, the subprocess returns code 1 and stderr is:

terminate called after throwing an instance of 'com::sun::star::deployment::DeploymentException'
Unspecified Application Error

This error indicates that there is something wrong with the installation. I have checked host info using both uname and /proc/cpuinfo and while the lambdas end up running on two variants of Xeon CPUs, there are no other differences.

My assumption is that the Libreoffice somehow ends up depending on a dynamic library from the host and that this particular library has different versions of different lambda hosts.

Any suggestions to how this could be resolved?

python

amazon-web-services

aws-lambda

libreoffice

0 Answers

Your Answer

Accepted video resources