在EC2实例上执行AWS Lambda run命令并获取结果 [英] AWS Lambda run command on EC2 instance and get result

查看:272
本文介绍了在EC2实例上执行AWS Lambda run命令并获取结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在运行一些进程的EC2实例。我也有通过各种方式触发的Lambda脚本。我希望这个Lambda脚本与我的EC2实例进行对话,并从中获取正在运行的进程的列表(基本上在EC2框中运行 ps aux 并读取输出)。

I have an EC2 instance that is running a few processes. I also have a Lambda script that is triggered through various means. I would like this Lambda script to talk to my EC2 instance and get a list of running processes from it (Essentially run ps aux on the EC2 box, and read the output).

现在,只需一个实例及其实例ID,这已经很容易了。只需SSH进入,运行命令,获取输出,就可以了。但是,我想将此扩展到多个EC2实例,对于这些实例,只有instance-id是已知的,并且可能无法提供SSH密钥。

Now this is easy enough with just one instance and its instance-id. Just SSH in, run the command, get the output, and be on my way. However, I would like to scale this to multiple EC2 instances, for which only the instance-id is known and SSH keys may not be given.

Lambda和Boto(或其他库)是否可以进行这种配置?还是只需要在每个实例上运行一个微型服务器,该微型服务器就会使用给定的信息进行回复(我确实在尝试避免这种情况)

Is such a configuration possible with Lambda and Boto (or other libraries)? Or do I just have to run a microserver on each of my instances that will reply with the given information (something I'm really trying to avoid)

推荐答案

您可以通过 AWS系统管理器-运行命令


AWS Systems Manager可为您的实例提供安全,可靠的远程管理,而无需登录服务器,而无需使用堡垒主机,SSH或远程PowerShell。

AWS Systems Manager provides you safe, secure remote management of your instances at scale without logging into your servers, replacing the need for bastion hosts, SSH, or remote PowerShell.

具体是:


  • 使用Lambda函数中的send-command API获取一组实例上所有进程的列表。您可以通过提供实例列表甚至标签查询来做到这一点

  • 您还可以使用CloudWatch Events直接触发运行命令

这篇关于在EC2实例上执行AWS Lambda run命令并获取结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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