shelf/lambda

编程入门 行业动态 更新时间:2024-10-03 08:18:04

<a href=https://www.elefans.com/category/jswz/34/465470.html style=shelf/lambda"/>

shelf/lambda

我正在尝试使用 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 上重新部署相同的映像后,这在一段时间内工作得很好,但之后它再次开始间歇性地失败,并出现上述错误。

回答如下:

更多推荐

shelf/lambda

本文发布于:2024-05-31 06:53:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1771389.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:shelf   lambda

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!