简体   繁体   English

如何在 lambda 上的 nodejs 中执行 ping 命令?

[英]How can I exec the ping command in nodejs on lambda?

This runs locally and returns the ping output:这在本地运行并返回 ping 输出:

var exec = require('child_process').exec;
function execute(command, callback){
    exec(command, function(error, stdout, stderr){ callback(stdout); });
}
execute("ping -c 3 localhost", function(name){
  console.log(name);
});

Running this in lambda it completes but I never see output:在 lambda 中运行它会完成,但我从未看到输出:

exports.handler = (event, context, callback) => {
    var exec = require('child_process').exec;
    function execute(command, callback){
        exec(command, function(error, stdout, stderr){ callback(stdout); });
    }
    execute("ping -c 3 localhost", function(name){
      console.log(name);
    });
};

How do I get it to show output?如何让它显示输出?

Sadly there is no way to do ICMP pings from inside AWS Lambda currently - the main issue is that the container environment that Lambdas run inside lacks the CAP_NET_RAW capability needed to allow an application to use raw sockets.遗憾的是,目前无法从 AWS Lambda 内部执行 ICMP ping - 主要问题是 Lambdas 在其中运行的容器环境缺乏允许应用程序使用原始套接字所需的 CAP_NET_RAW 功能。

There's no way around this, even trying to use the command line ping utility inside the Amazon Linux container the Lambda runs inside of won't work.没有办法解决这个问题,即使尝试在运行 Lambda 的 Amazon Linux 容器内使用命令行 ping 实用程序也不起作用。

Source: https://github.com/jethrocarr/lambda-ping .来源: https : //github.com/jethrocarr/lambda-ping They also proposed a solution you can try.他们还提出了一个您可以尝试的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM