shelf/lambda-libreoffice-base:7.4-node16-x86_64 lambda 图像间歇性中断

问题描述 投票:0回答:0

我正在尝试使用 libreoffice 库的 lambda 函数将 word 转换为 PDF。为此,我按照此 github repo 的 README 文件中的说明创建了一个自定义 docker 映像,该映像使用 Shelf/lambda-libreoffice-base:7.4-node16-x86_64 作为基础映像。大部分时间都工作正常,但偶尔会出现故障。

这是我的 docker 镜像的代码:

FROM public.ecr.aws/shelf/lambda-libreoffice-base:7.4-node16-x86_64

COPY ./fonts/* /usr/local/share/fonts/
COPY ./ ./
RUN yum install java-1.8.0-openjdk-devel -y
CMD [ "app.handler" ]

这是我的处理函数:

const handler = async (event) => {
  try {
    const {fileUrl, isExcel} = event;

    const inputFileExtension = ".docx";
    const fileName = `template-${uuidv4()}${inputFileExtension}`;
    await download(fileUrl, `/tmp/${fileName}`);
    const pdfFilePath = convertTo(fileName, 'pdf');
    const stats = fs.statSync(pdfFilePath);
    const pdfFileData = fs.readFileSync(pdfFilePath);
  
    await clearTmpDirectory();
    const response = {
      statusCode: 200,
      body: pdfFileData
    };
    return response;
  } catch (err) {
    console.error(err);
    throw err;
  }
}

这里的下载函数只是从传递给它的url下载我的文件,而clearTmpDirectory函数只是清除tmp目录中的所有文件。

这是我间歇性遇到的错误:

javaldx: Could not find a Java Runtime Environment!

what():  osl::Thread::create failed

terminate called after throwing an instance of 'std::runtime_error'

Error: Command failed: cd /tmp && libreoffice7.4 --headless --invisible --nodefault --view --nolockcheck --nologo --norestore --convert-to pdf --outdir /tmp /tmp/template-bf853fb4-95d9-4fef-87b1-59c54cf13c58.docx
javaldx: Could not find a Java Runtime Environment!
Warning: failed to read path from javaldx
terminate called after throwing an instance of 'std::runtime_error'
  what():  osl::Thread::create failed

    at checkExecSyncError (node:child_process:861:11)
    at execSync (node:child_process:932:15)
    at convertTo (/var/task/node_modules/@shelf/aws-lambda-libreoffice/lib/convert.js:29:40)
    at Runtime.handler (/var/task/app.js:66:25) {
  status: 134,
  signal: null,
  output: [
    null,
    <Buffer >,
    <Buffer 6a 61 76 61 6c 64 78 3a 20 43 6f 75 6c 64 20 6e 6f 74 20 66 69 6e 64 20 61 20 4a 61 76 61 20 52 75 6e 74 69 6d 65 20 45 6e 76 69 72 6f 6e 6d 65 6e 74 ... 150 more bytes>
  ],
  pid: 12370,
  stdout: <Buffer >,
  stderr: <Buffer 6a 61 76 61 6c 64 78 3a 20 43 6f 75 6c 64 20 6e 6f 74 20 66 69 6e 64 20 61 20 4a 61 76 61 20 52 75 6e 74 69 6d 65 20 45 6e 76 69 72 6f 6e 6d 65 6e 74 ... 150 more bytes>
}

注意:在我在 lambda 上重新部署相同的映像后,这在一段时间内工作得很好,但之后它再次开始间歇性地失败,并出现上述错误。

node.js docker aws-lambda libreoffice
© www.soinside.com 2019 - 2024. All rights reserved.