将Lambda函数更新为新的运行时.为什么cURL在AWS Lambda的节点10中不再起作用? [英] Updating Lambda function to new runtime. Why is cURL no longer working in Node 10 on AWS Lambda?

查看:317
本文介绍了将Lambda函数更新为新的运行时.为什么cURL在AWS Lambda的节点10中不再起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的Lambda函数中引发错误的行:

This is the line in my Lambda function that's raising an error:

// running in Node 8
const { execSync } = require('child_process');
execSync('curl https://github.com');

我正在尝试将Lambda函数从Node 8升级到Node 10或Node 12,因为Lambda上的Node 8在2019年12月底被弃用(因此我将无法对其进行更新).但是,当我深入查看CloudWatch日志时,会看到以下错误:

I'm trying to upgrade my Lambda function from Node 8 to Node 10 or Node 12, since Node 8 on Lambda is being deprecated at the end of December, 2019 (so I won't be able to update it). However, when I dig into my CloudWatch logs I'm seeing the following error:

bin/sh: curl: command not found

当我将Lambda函数更新为仅运行which curl时,我得到了类似的错误: bin/sh: which: command not found

And when I update my Lambda function to just run which curl I get a similar error: bin/sh: which: command not found

每个文档此处,我知道Node 8 +,Python 3.8+和Java 11+正在使用新的AWS Lambda Runtime Amazon Linux2.

Per documentation here, I know that Node 8+, Python 3.8+ and Java 11+ are using the new AWS Lambda Runtime, Amazon Linux 2.

感谢您的帮助.

推荐答案

以上节点V10和V12基于Amazon Linux 2,您无法运行curl.

Node V10 and V12 above is based on Amazon Linux 2 and you can not run curl.

AWS Lambda上的cURL给出未找到命令错误

您有两个选择

  • 在AWS Lambda中使用本机二进制程序包
  • 使用nodejs 请求或http内置模块
  • Use native binary package in AWS Lambda
  • Use nodejs request or http built-in module

如何在AWS Lambda部署程序包中使用Amazon Linux AMI本机二进制程序包?

简短说明

Lambda部署程序包是一个.zip文件,其中包含您的代码和 任何依赖关系. Lambda执行环境基于 特定的Amazon Linux AMI和内核版本.任何本机二进制文件 Lambda部署程序包中使用的命令必须在此编译 环境,并且仅支持64位二进制文​​件.

A Lambda deployment package is a .zip file that contains your code and any dependencies. The Lambda execution environment is based on a specific Amazon Linux AMI and kernel version. Any native binaries that are used in a Lambda deployment package must be compiled in this environment, and only 64-bit binaries are supported.

要使用Amazon Linux AMI本机二进制软件包,您可以提取 64位库,然后将它们包括在Lambda部署中 包裹. (本文未介绍的另一种选择是 将源代码下载到共享库,然后重新编译 包.)

To use the Amazon Linux AMI native binary packages, you can extract the 64-bit libraries and then include them in your Lambda deployment package. (Another option, that is not covered in this article, is to download the source code to the shared library and then recompile the package.)

lambda运行时

因此,如注释中所建议,另一种方法是使用节点包.

So as suggested in the comment the other way is to use the node package.

您可以尝试进行测试,例如

you can try for testing purpose something like

exports.handler = async (event) => {
  const https = require('https');                
  var response=https.get('https://api.github.com');
  return JSON.stringify(response.output)
}

这篇关于将Lambda函数更新为新的运行时.为什么cURL在AWS Lambda的节点10中不再起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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