运行 bash 来自节点 AWS Lambda 函数的脚本
Run bash script from node AWS Lambda function
我有一个节点 lambda 函数,我从中 运行 宁一个 bash 脚本。
'use strict';
const exec = require('child_process').exec;
exports.handler = (event, context, callback) => {
const message = event.message;
const child = exec('./bs.sh ' + message, function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
});
};
当我 运行 这个时,我得到 /bin/sh: ./bs.sh: Permission denied
。在压缩函数之前,我尝试使用 chmod 777 bs.sh
更改权限,但这也没有用。是 lambda 的限制还是我的方法有误?
你会想看看
https://aws.amazon.com/blogs/compute/running-executables-in-aws-lambda/
特别是这一点:
Including your own executables is easy; just package them in the ZIP file you upload, and then reference them (including the relative path within the ZIP file you created) when you call them from Node.js or from other processes that you’ve previously started. Ensure that you include the following at the start of your function code:
process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT']
我有一个节点 lambda 函数,我从中 运行 宁一个 bash 脚本。
'use strict';
const exec = require('child_process').exec;
exports.handler = (event, context, callback) => {
const message = event.message;
const child = exec('./bs.sh ' + message, function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
});
};
当我 运行 这个时,我得到 /bin/sh: ./bs.sh: Permission denied
。在压缩函数之前,我尝试使用 chmod 777 bs.sh
更改权限,但这也没有用。是 lambda 的限制还是我的方法有误?
你会想看看
https://aws.amazon.com/blogs/compute/running-executables-in-aws-lambda/
特别是这一点:
Including your own executables is easy; just package them in the ZIP file you upload, and then reference them (including the relative path within the ZIP file you created) when you call them from Node.js or from other processes that you’ve previously started. Ensure that you include the following at the start of your function code:
process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT']