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}`;
};