title: Retrieving command invocation in AWS SSM
body: <p>I am trying to send command to a running ubuntu ec2 instance. I have configured the appropriate role and I have an ssm agent running on the ec2 instance. Using the boto3 SDK I am able to use the <code>client.send_command()</code> function to successfully send a shell command and was subsequently able to get the command Id. Now the challenge is polling for the result. I am trying to use the  <code>client.get_command_invocation()</code> function but keep getting a <code>InvocationDoesNotExist</code> error. I am confident that I am using the correct command ID and instance ID because I have tested these using the AWS CLI as in  <code>aws ssm list-command-invocations --command-id #### --instance-id i-#####</code> and this worked. Here is a snippet of my code:</p>
  
  <pre><code>`ssm_client = boto3.client('ssm')
  target_id = "i-####"
  response = ssm_client.send_command(
              InstanceIds=[
                  target_id 
                      ],
              DocumentName="AWS-RunShellScript",
              Comment="Code to run" ,
              Parameters={
                      "commands": ["ls -l"]
                          }
              )
  cmd_id= response['Command']['CommandId']
  response = ssm_client.get_command_invocation(CommandId=cmd_id, 
  InstanceId=target_id)
  print(response)`
  </code></pre>
  
  <p>Here is the returned error:
  <code>botocore.errorfactory.InvocationDoesNotExist: An error occurred (InvocationDoesNotExist) when calling the GetCommandInvocation operation</code></p>
  
  <p>Thanks in advance.</p>