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, 2020 in AWS by akhtar
• 38,260 points
10,666 views

1 answer to this question.

0 votes

Hi@akhtar,

Boto represents an Amazon Web Services (AWS) SDK that is available for Python. It allows Python developers to design configuration, manage, and configure AWS services, including EC2 as well as S3. Boto provides an easy-to utilize, object-oriented API and also the ability to access low level AWS services. You can even check out the details from the AWS Course.

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, 2020 by MD
• 95,460 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
• 58,020 points
3,597 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
1,950 views
0 votes
1 answer
+1 vote
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP