How to execute commands on AWS Instance using Boto3?

0 votes

Hi Guys,

I have launched one EC2 instance for Windows. Now I want to run some command in this instance using the boto3 module. How can I do that?

Oct 7 in AWS by akhtar
• 33,720 points
235 views

1 answer to this question.

0 votes

Hi@akhtar,

You can use the boto3 module to do this. Boto3 module has arguments named send_command. It helps you to run commands in EC2 instance.

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)
answered Oct 7 by MD
• 79,930 points

Related Questions In AWS

0 votes
1 answer

How to Pass the VPC ID while creating the Ec2 instance in AWS using Python Boto3

import boto3 ec2 = boto3.resource('ec2') instance = ec2.create_instances( ...READ MORE

answered Jan 29, 2019 in AWS by Priyaj
• 57,700 points
1,126 views
0 votes
1 answer
+1 vote
2 answers

How to launch and access an instance using AWS-CLI?

aws ec2 run-instances --image-id ami-id --key-name yourkeyname ...READ MORE

answered Feb 23, 2019 in AWS by Shashank
• 1,370 points
566 views
0 votes
1 answer
+1 vote
1 answer