从Nodejs在EC2实例上运行Linux命令

时间:2017-07-10 13:47:31

标签: node.js linux amazon-web-services amazon-ec2 aws-sdk

我在Node.js中获得了一些Amazon EC2云实例(DescribeInstances)。如何在实例上执行命令?操作系统应该是Linux,所以我想执行例如“ps -ef”命令......

1 个答案:

答案 0 :(得分:0)

It's hard to tell given the question what context this execution is in. If you're talking about NodeJS on the instance you want to run the command then NodeJS has a few ways to execute shell commands, one of which is already provided in the comments to your question.

Now if you have NodeJS using the AWS SDK outside of the instance you want to run the command on, there's using SSH to run the command if you want to do it through NodeJS. If you want to use the SDK instead, there's Systems Manager Run Command. AWS JS SDK interfaces with SSM through the AWS.SSM class. Another benefit to this is you can utilize roles to provide overall permissions versus needing to worry about SSH authentication.