gpt4 book ai didi

amazon-web-services - "Invalid ELF header"在 AWS Lambda 上使用 libxmljs

转载 作者:行者123 更新时间:2023-12-04 00:14:09 26 4
gpt4 key购买 nike

我有一个使用无服务器、express 和 libxmljs 的 super 基本 AWS Lambda 函数(将 JavaScript 绑定(bind)到 libxml):

代码

无服务器.xml:

service: xmltest

provider:
name: aws
runtime: nodejs10.x
stage: dev
region: us-east-1

functions:
app:
handler: index.handler
events:
- http: ANY /
- http: 'ANY {proxy+}'

plugins:
- serverless-offline

index.js:
const serverless = require('serverless-http');
const express = require('express');
const libxml = require("libxmljs");

const app = express();

app.use(express.json());

app.post('/lookup', async function (req, res) {
res.send({result: "hello world"});
});

module.exports.handler = serverless(app);

在本地工作,但不能在 AWS 上工作

当我在本地运行时:
$ curl -X POST http://localhost:3000/lookup -d {"example":123}

{"result":"hello world"}

当我在 AWS 上运行时:
$ curl -X POST https://REDACTED.execute-api.us-east-1.amazonaws.com/dev/lookup -d {"example":123}

{"message": "Internal server error"}

CloudWatch 日志说:
2019-06-05T12:46:43.280Z    undefined   ERROR   Uncaught Exception
{
"errorType": "Error",
"errorMessage": "/var/task/node_modules/libxmljs/build/Release/xmljs.node: invalid ELF header",
"stack": [
"Error: /var/task/node_modules/libxmljs/build/Release/xmljs.node: invalid ELF header",
" at Object.Module._extensions..node (internal/modules/cjs/loader.js:730:18)",
" at Module.load (internal/modules/cjs/loader.js:600:32)",
" at tryModuleLoad (internal/modules/cjs/loader.js:539:12)",
" at Function.Module._load (internal/modules/cjs/loader.js:531:3)",
" at Module.require (internal/modules/cjs/loader.js:637:17)",
" at require (internal/modules/cjs/helpers.js:22:18)",
" at bindings (/var/task/node_modules/bindings/bindings.js:84:48)",
" at Object.<anonymous> (/var/task/node_modules/libxmljs/lib/bindings.js:1:99)",
" at Module._compile (internal/modules/cjs/loader.js:701:30)",
" at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)"
]
}

问题

如何在 AWS 上导入 libxmljs?

我看到一些相关的问题,例如
  • aws - “Unable to import module 'process': /var/task/numpy/core/multiarray.so: invalid ELF header”
  • “invalid ELF header” when using the nodejs “ref” module on AWS Lambda

  • 所以我猜测 libxmljs 中的某些东西是为与 Amazon Linux 不同的架构(我的本地机器是 macOS)而构建的。但我不确定如何解决这个问题?

    最佳答案

    我通过运行 npm install 解决了这个问题在 Linux 机器上而不是我的 Mac 上。

    就我而言,我设置了 AWS CodePipeline,它在 EC2 实例上运行所有构建脚本。也可以使用其他托管的 CI 管道、Docker 容器等来解决这个问题。

    关于amazon-web-services - "Invalid ELF header"在 AWS Lambda 上使用 libxmljs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56460986/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com