[英]How can I execute linux command inside EC2 using AWS CLI
I have some EC2 instances running on AWS.我有一些在 AWS 上运行的 EC2 实例。 I am able to get the instance details and start and stop the instance using the AWS CLI command.我可以使用 AWS CLI 命令获取实例详细信息并启动和停止实例。 I was looking for a way to execute a few Linux commands inside the AWS EC2 instances using CLI.我正在寻找一种使用 CLI 在 AWS EC2 实例中执行一些 Linux 命令的方法。
Actually, I am creating a Jenkins pipeline which stops and starts the EC2 instance using AWS CLI.实际上,我正在创建一个 Jenkins 管道,它使用 AWS CLI 停止和启动 EC2 实例。 But I also need to execute a few commands after the EC2 is started.但是我还需要在 EC2 启动后执行一些命令。
I tried using the aws ssm send-command
but it seems this command is not working for me.我尝试使用aws ssm send-command
,但似乎该命令对我不起作用。 I tried the below example command and got the error.我尝试了下面的示例命令并得到了错误。
aws ssm send-command \
--instance-ids "instance-ID" \
--document-name "AWS-RunShellScript" \
--comment "IP config" \
--parameters commands=ifconfig \
--output text
Error:错误:
An error occurred (InvalidInstanceId) when calling the SendCommand operation: Instances [[i-xxxx]] not in a valid state for account XXXXXXXX
Is there any alternate approach to executing commands using AWS CLI?是否有任何替代方法可以使用 AWS CLI 执行命令?
Is your EC2 instance viewable in Systems Manager?您的 EC2 实例是否可以在 Systems Manager 中查看? You won't be able to use aws ssm send-command
if your EC2 instance can't talk to Systems Manager.如果您的 EC2 实例无法与 Systems Manager 对话,您将无法使用aws ssm send-command
。
Make sure your EC2 instance has the following roles:确保您的 EC2 实例具有以下角色:
Make sure you EC2 can access the following internet domains (or VPC endpoints):确保您的 EC2 可以访问以下 Internet 域(或 VPC 终端节点):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.