从今天开始几个小时,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;
};
Run Code Online (Sandbox Code Playgroud)
我收到一个 /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)"
]
}
Run Code Online (Sandbox Code Playgroud)
最后,我从 Amazon 支持(及其内部技术团队)那里得到确认,CURL 二进制文件不再包含在基于 Amazon Linux 2 的 AWS Lambda 环境中。这就是我无法使用 execSync 或 spawnSync 执行 curl 的原因在节点 10 和节点 12 中。
根据他们的替代方案是使用“请求”库https://github.com/request/request/blob/master/README.md#streaming
| 归档时间: |
|
| 查看次数: |
4142 次 |
| 最近记录: |