从今天开始几个小时,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: 命令未找到错误
知道问题是什么吗?
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)"
]
}
最后,我得到了 Amazon 支持(及其内部技术团队)的确认,即 CURL 二进制文件不再作为基于 Amazon Linux 2 的 AWS Lambda 环境的一部分包含在内。这就是为什么我无法使用 execSync 或 spawnSync 执行curl在节点 10 和节点 12 中。
他们的替代方案是使用“requests”库https://github.com/request/request/blob/master/README.md#streaming
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)