Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InvalidInstanceId: An error occurred (InvalidInstanceId) when calling the SendCommand operation

The below is the code which i am running from python to execute commands in aws ec2 instance

import boto3
ec2 = boto3.client('ssm',region_name='us-east-1',aws_access_key_id='xxxxxxxxxxxxxxx',aws_secret_access_key='xxxxxxxxx')
a = ec2.send_command(InstanceIds=ids, DocumentName='AWS-RunShellScript', Comment='abcdabcd', Parameters={"commands":["ifconfig"]})

But it is giving the below error

InvalidInstanceId: An error occurred (InvalidInstanceId) when calling the SendCommand operation: 
like image 266
Teja Avatar asked Oct 31 '17 11:10

Teja


People also ask

What is AmazonSSMManagedInstanceCore?

AmazonSSMManagedInstanceCore – Instance trust policy that allows a node to use Systems Manager service core functionality. AmazonSSMServiceRolePolicy – Service role policy that provides access to AWS resources managed or used by Systems Manager.


1 Answers

The following scenarios can result in this error message:

  • Instance id is invalid (in the comments you have verified it isn't)
  • Instance is in a different region (in the comments you have verified it isn't)
  • Instance is not currently in the Running state
  • Instance does not have the AWS SSM agent installed and running.

You need to login to the AWS EC2/SSM console and make sure the instance(s) you are trying manage show up in the SYSTEMS MANAGER SHARED RESOURCES - Managed Instances list, and that they show a Ping status of Online. If not, you need to fix that before trying to send commands to the instance(s) in question.

like image 144
Mark B Avatar answered Oct 14 '22 11:10

Mark B