Closed scorobogaci closed 2 years ago
might be important or not, the docker image was built on MacBook Pro M1, with the following command
docker buildx build --platform linux/amd64 -f ./Dockerfile -t pdf-conversion-service .
building the docker image with the following command, fails inside lambda as well after invoke
docker build -t test-lambda-base-image .
starting container on host , and invoking command fails as well
Wanted to create a pull request, but was not able to, cannot push to the repository. However, here is the version of docker image which works ok, added java-1.8.0-openjdk
Dockerfile
FROM public.ecr.aws/lambda/nodejs:16-x86_64
# binutils is needed for "strip" command
RUN yum install \
java-1.8.0-openjdk \
tar \
gzip \
libdbusmenu.x86_64 \
libdbusmenu-gtk2.x86_64 \
libSM.x86_64 \
xorg-x11-fonts-* \
google-noto-sans-cjk-fonts.noarch \
binutils.x86_64 \
-y && \
yum clean all
RUN set -xo pipefail && \
curl "https://ftp.halifax.rwth-aachen.de/tdf/libreoffice/stable/7.3.4/rpm/x86_64/LibreOffice_7.3.4_Linux_x86-64_rpm.tar.gz" | tar -xz
RUN cd LibreOffice_7.3.4.2_Linux_x86-64_rpm/RPMS && \
yum install *.rpm -y && \
rm -rf /var/task/LibreOffice_7.3.4* && \
cd /opt/libreoffice7.3/ && \
strip ./**/* || true
@scorobogaci it worked for me when I set the env var HOME=/tmp
without installing Java
Could you please try does it work w/o Java?
I added this to the troubleshooting section: https://github.com/shelfio/libreoffice-lambda-base-image#troubleshooting
@scorobogaci it worked for me when I set the env var
HOME=/tmp
without installing JavaCould you please try does it work w/o Java?
sure, let me give it a try this option as well
@vladgolubev , you mean setting environment for lambda, not inside Dockerfile ? Thanks
@scorobogaci I tried in Lambda, but probably setting this in Dockerfile will yield the same effect?
@vladgolubev , tried with both options, setting ENV HOME=/tmp inside Dockerfile as well as setting lambda environment variable, getting this error in both cases
{
"errorMessage": "RequestId: 3fd15b21-394d-4feb-97e8-dffffe7b9b2c Error: Runtime exited with error: exit status 142",
"errorType": "Runtime.ExitError"
}
@scorobogaci could you please try a full handler file like this?
The handler sample in README was previously stripped down to show only the handle content. Here is a full handler
const {execSync} = require('child_process');
const {writeFileSync} = require('fs');
module.exports.handler = () => {
writeFileSync('/tmp/hello.txt', Buffer.from('Hello World!'));
execSync(`
cd /tmp
libreoffice7.3 --headless --invisible --nodefault --view --nolockcheck --nologo --norestore --convert-to pdf --outdir /tmp ./hello.txt
`);
};
@vladgolubev , ignore previous comment, it was because i did not set the correct entrypoint for lambda, let me do another test
your sample worked
this worked, having HOME=/tmp set as lambda environment variable . However, Billed Duration: 33073 ms
, this is crazy... how come on cold start there is such enormous delay ?
@vladgolubev , performs really well when lambda is in WARM state, however on COLD state, is taking 30 seconds, how come? Why this would be the case ?
@scorobogaci libreoffice when first booted, writes some files to disk. Maybe it's worth exploring adding a "smoke startup" for LibreOffice during docker image build so those files will be bundled in the docker image. You can try that and see does it help with a cold start
@vladgolubev , alright thanks for suggestion ! this is crucial i think, otherwise the solution cannot be used in a serverless model, cause on COLD starts 30 seconds is not acceptable at all :( Feel free to close the issue, adding HOME=/tmp as lambda environment variable solves the issue.
Would be nice to check if adding ENV HOME=/tmp in Dockerfile solves also the issue, having this config in Dockerfile removes the need for developers to take care of setting lambda environment variable
Thanks a lot !
@scorobogaci thanks for noticing it! When I get to touch my code using this docker image next time, I'll check does it work with env var in Dockerfile. Feel free to update if you got success with reducing a cold start as well!
Steps to reproduce : Dockerfile
index.js
Output of lambda after execution
Expected behaviour
Lambda created built based on this docker image should not fail and be able to do the conversion