How to execute commands on AWS Instance using Boto3

后端 未结 6 1474
一生所求
一生所求 2021-01-11 12:01

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

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

6条回答
  •  旧巷少年郎
    2021-01-11 12:24

    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)
    

提交回复
热议问题