Install libreoffice on lambda nodejs 12.0 but can not run command when deployed

Viewed 514

I try to install libreoffice to docker image of lambda function. When I run it on local machine it work fine but when deployed the image to lambda function, It keeps saying "failed to read path from javaldx" and can not open soffice. Are there any solution to fix this? Here is DockerFile:

FROM public.ecr.aws/lambda/nodejs:12

RUN yum install wget tar -y
RUN yum install java-1.8.0-openjdk-devel -y
RUN mkdir "LibreOffice_7.2_Linux_x86-64_rpm"
ADD LibreOffice_*_Linux_x86-64_rpm ./LibreOffice_7.2_Linux_x86-64_rpm
RUN ls -la
RUN cd  LibreOffice_*_Linux_x86-64_rpm && cd RPMS && yum -y localinstall *.rpm
RUN chmod -R 777 /opt/libreoffice7.2
ADD test.docx ./
RUN export HOME=/tmp

COPY index.js package*.json ./
RUN npm install

CMD [ "index.handler" ]

Here is my handler code:

/* Amplify Params - DO NOT EDIT
    ENV
    REGION
    STORAGE_DOCBACKENDD3C9A483_BUCKETNAME
Amplify Params - DO NOT EDIT */

const {writeFileSync, readFileSync} = require('fs');
const {execSync} = require('child_process');
const {S3} = require('aws-sdk');

const s3 = new S3(
    {
        params: {
            Bucket: "documentgenerationb25c0536d4054b9faeafca747e3f295559-dev",
            apiVersion: '2006-03-01'
        }
    }
);
const convertCommand = `/opt/libreoffice7.2/program/soffice --convert-to pdf test.docx --headless`;

exports.handler = async () => {
    const filename = "test.docx"
    const {Body: inputFileBuffer} = await s3.getObject({Key: `public/${filename}`}).promise();
    writeFileSync(`/tmp/${filename}`, inputFileBuffer);

    execSync(`${convertCommand} ${filename}`);
    const outputFilename = `test1-brandon.pdf`;
    const outputFileBuffer = readFileSync(`/tmp/${outputFilename}`);

    await s3
    .putObject({
        Key: `public/${outputFilename}`, Body: outputFileBuffer,
        ACL: 'public-read', ContentType: 'application/pdf'
    })
    .promise();

    return `https://documentgenerationb25c0536d4054b9faeafca747e3f295559-dev.s3.amazonaws.com/public/${outputFilename}`;
};

2 Answers

Looks like this answer Warning: failed to read path from javaldx applies to your case too.

Your user doesn't has a home folder set, or the home folder is not writeable. I just switched from calling libreoffice directly to calling it via a shell script

Related