gpt4 book ai didi

mysql - 即使安装了节点模块,Lambda 函数也失败并提示 "mysql"命令未找到

转载 作者:行者123 更新时间:2023-11-29 18:23:58 24 4
gpt4 key购买 nike

我正在编写一个 lambda,它将我的数据库架构恢复到 RDS 中。我在 aws lambda 控制台上上传的 zip 中打包了节点模块。这里有什么问题吗?我哪里出错了?

这是我的 lambda 函数

var  MysqlTools= require('mysql-tools');
var endpoint = process.env.MYSQLDB_HOST;
var username = process.env.MYSQLDB_USER;
var database = process.env.MYSQLDB_DATABASE;
var password = process.env.MYSQLDB_PASSWORD;

exports.restore = (event,context)=>{
var tool = new MysqlTools();
tool.restoreDatabase({host: endpoint, user: username, password:password, sqlFilePath: 'epmoliteDump.sql', database: database
}, function (error, output, message) {
if (error instanceof Error) {
console.log(error);
} else {
console.log(output);
console.log(message);
}
});
}

云 watch 错误日志

START RequestId: 303cd306-9ed3-11e7-874e-a5a3ce668160 Version: $LATEST 2017-09-21T13:45:54.531Z 303cd306-9ed3-11e7-874e-a5a3ce668160 { Error: Command failed: mysql -h me10uo7cwmpj.c8icuw7t60la.us-east-1.rds.amazonaws.com -u xxxxxx -pxxxxxx eLite_DB

at ChildProcess.exithandler (child_process.js:204:12)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:886:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5) killed: false, code: 127,

signal: null, cmd: 'mysql -h me10uo7cwmpj.c8icuw7t60la.us-east-1.rds.amazonaws.com -u xxxxxx -pxxxxxx eLite_DB

最佳答案

您不能使用mysql-tools因为它期望您拥有 mysql $PATH 中的实用程序,并且似乎无法在 mysql-tools 中配置它.

但是,您可以包含 mysql Lambda 包中的二进制文件,前提是它是为匹配版本的 Amazon Linux 构建的。

假设二进制文件的位置位于<root directory of lambda function>/bin/mysql ,您可以像这样更改代码:

const exec = require('child_process').exec
const endpoint = process.env.MYSQLDB_HOST;
const username = process.env.MYSQLDB_USER;
const database = process.env.MYSQLDB_DATABASE;
const password = process.env.MYSQLDB_PASSWORD;

exports.restore = (event, context) => exec(`${process.env['LAMBDA_TASK_ROOT']}/bin/mysql -u ${username} -p${password} -h ${endpoint} ${database} < epmoliteDump.sql`, function (error, output, message) {
if (error instanceof Error) {
console.log(error);
} else {
console.log(output);
console.log(message);
}
});

关于mysql - 即使安装了节点模块,Lambda 函数也失败并提示 "mysql"命令未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46345987/

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