如何使用Boto3在AWS实例上执行命令 [英] How to execute commands on AWS Instance using Boto3

查看:193
本文介绍了如何使用Boto3在AWS实例上执行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我是否可以在启动的AWS实例上使用Boto3执行Shell命令.

Can anyone tell me if we can execute Shell Commands using Boto3 on Launched AWS instance.

我在少数地方阅读过有关"boto.manage.cmdshell"的信息,但Boto3中已弃用了它.

I read at few places about "boto.manage.cmdshell" but it is deprecated in Boto3.

感谢任何帮助.

关于, 索拉比(Suurabh)

Regards, Saurabh

推荐答案

ssm_client = boto3.client('ssm')
response = ssm_client.send_command(
            InstanceIds=['i-03#####'],
            DocumentName="AWS-RunShellScript",
            Parameters={'commands': ['start ecs']}, )

command_id = response['Command']['CommandId']
output = ssm_client.get_command_invocation(
      CommandId=command_id,
      InstanceId='i-03######',
    )
print(output)

这篇关于如何使用Boto3在AWS实例上执行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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