title: Run a private AMI ec2 instance from boto
body: <p>I have been looking for a solution to my problem for two days, but I don’t have any hint of what I am doing wrong with running a private AMI as an EC2 instance using boto. I haven’t seen any page explaining clearly how to do it, or anybody with my problem.</p>
  
  <p>To explain more clearly my problem: </p>
  
  <ul>
  <li><p>I have created a custom AMI on the web interface (installed some packages, added some files)</p></li>
  <li><p>Now I would like to automate the tasks I am performing on the AMI using a Python script on my computer (and if possible, run several instances of this specific AMI)</p></li>
  <li><p>I have written the following sample code:</p>
  
  <pre><code>import boto.ec2
  
  conn = boto.ec2.connect_to_region("eu-west-1",
    aws_access_key_id='myAKI',aws_secret_access_key='MySK')
  
  print (conn)
  
  reservation=conn.run_instances(image_id='ami-XXXXX',
    instance_type='m1.small',key_name='MyKey')
  </code></pre></li>
  </ul>
  
  <p>When I run this code I get an error:</p>
  
  <pre><code>EC2Connection:ec2.eu-west-1.amazonaws.com
  Traceback (most recent call last):
    File "./myfile.py", line 6, in &lt;module&gt;
      reservation=conn.run_instances(image_id='ami-  XXXX',instance_type='m1.small',key_name='MyKey')
    File "/Library/Python/2.7/site-packages/boto-2.8.0-py2.7.egg/boto/ec2/connection.py", line 722, in run_instances
  verb='POST')
    File "/Library/Python/2.7/site-packages/boto-2.8.0-py2.7.egg/boto/connection.py", line   1062, in get_object
      raise self.ResponseError(response.status, response.reason, body)
  boto.exception.EC2ResponseError: EC2ResponseError: 400 Bad Request
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Response&gt;&lt;Errors&gt;&lt;Error&gt;&lt;Code&gt;AuthFailure&lt;/Code&gt;&lt;Message&gt;Not authorized for images: [ami- XXXXXXX]&lt;/Message&gt;&lt;/Error&gt;&lt;/Errors&gt;&lt;RequestID&gt;6b653488-332d-4251-abb2-8e7e96e91891&lt;/RequestID&gt;    &lt;/Response&gt;
  </code></pre>
  
  <p>Does anybody has any idea about how to proceed? I assume that there is maybe a connection problem, but I can get a list of public images. I don’t know how to go further on the debug.</p>