我正在编写一个将我的数据库模式恢复为RDS的lambda。我已经在我已经在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);
}
});
}
Cloud watch错误日志
START RequestId:303cd306-9ed3-11e7-874e-a5a3ce668160版本:$ LATEST 2017-09-21T13:45:54.531Z 303cd306-9ed3-11e7-874e-a5a3ce668160 {错误: 命令失败: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
答案 0 :(得分:0)
您无法使用mysql-tools
,因为它希望您在$ PATH中拥有mysql
实用程序,并且似乎无法在mysql-tools
中配置它。
但是,您可以在Lambda包中包含mysql
二进制文件,前提是它是为匹配的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);
}
});