AWS Lambda上的cURL给出命令未找到错误 [英] cURL on AWS Lambda gives command not found error

查看:129
本文介绍了AWS Lambda上的cURL给出命令未找到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天开始几个小时,在Lambda上执行简单的curl命令失败.
Lambda环境是NodeJs 10.x(也已在12.x中试用过).

Starting a few hours today, a simple curl command on Lambda is failing.
Lambda environment is NodeJs 10.x (have also tried in 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:找不到命令错误 知道是什么问题吗?

I get a /bin/sh curl: command not found error Any idea what the issue is?

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的AWS Lambda环境中. 2.这就是为什么我无法在节点10和节点12中使用execSync或spawnSync执行卷曲的原因.

Finally i have a confirmation from Amazon support (and their internal tech team) that CURL binary is no longer included as part of the AWS Lambda environment based on Amazon Linux 2. Which is why I am not able to perform curl using either execSync or spawnSync in Node 10 and Node 12.

按照他们的选择是使用请求"库 https://github.com/request/request/blob/master/README.md#streaming

The alternative as per them is to use the "requests" library https://github.com/request/request/blob/master/README.md#streaming

这篇关于AWS Lambda上的cURL给出命令未找到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆