从今天开始的几个小时里,Lambda上的一个简单的curl命令失败了。
Lambda环境是NodeJs 10.x(也尝试过12.x)。
const { execSync } = require('child_process');
exports.handler = async (event) => {
execSync('curl http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg -o /tmp/BigBuckBunny.jpg');
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return response;
};
我收到了"/bin/sh curl: command not found"的错误信息,你有任何想法是什么问题吗?
Response:
{
"errorType": "Error",
"errorMessage": "Command failed: curl http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg -o /tmBigBuckBunny.jpg\n/bin/sh: curl: command not found\n",
"trace": [
"Error: Command failed: curl http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg -o /tmBigBuckBunny.jpg",
"/bin/sh: curl: command not found",
"",
" at checkExecSyncError (child_process.js:621:11)",
" at execSync (child_process.js:657:15)",
" at Runtime.exports.handler (/var/task/index.js:11:4)",
" at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
]
}
$PATH
变量没有设置正确。也许你可以将/usr/bin/curl
添加到命令中?(或者添加正确的完整路径)删除之前的评论。祝你好运。(像往常一样;-)). - shellter