我尝试安装libreoffice来停靠lambda函数的镜像。当我在本地机器上运行它时,它工作得很好,但当将图像部署到lambda函数时,它总是说“无法从javaldx读取路径”,并且无法打开soffice。有什么解决方案可以解决这个问题吗?下面是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" ]下面是我的处理程序代码:
/* 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}`;
};发布于 2021-09-27 23:38:20
看起来这个答案Warning: failed to read path from javaldx也适用于你的案例。
您的用户没有设置主文件夹,或者主文件夹不可写。我刚从直接调用libreoffice切换到通过shell脚本
调用它
发布于 2022-01-20 22:14:24
我目前正在使用这个带有lambda层的https://github.com/shelfio/aws-lambda-libreoffice,你只需要安装@shelf/aws-lambda-libreoffice。因此,它实际上只需要4行代码即可实现无服务器部署。
https://stackoverflow.com/questions/69343801
复制相似问题