Reputation: 57
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.
To explain more clearly my problem:
I have created a custom AMI on the web interface (installed some packages, added some files)
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)
I have written the following sample 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')
When I run this code I get an error:
EC2Connection:ec2.eu-west-1.amazonaws.com
Traceback (most recent call last):
File "./myfile.py", line 6, in <module>
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
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>AuthFailure</Code><Message>Not authorized for images: [ami- XXXXXXX]</Message></Error></Errors><RequestID>6b653488-332d-4251-abb2-8e7e96e91891</RequestID> </Response>
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.
Upvotes: 2
Views: 1691
Reputation: 45856
I think it is trying to tell you that the account credentials that are associated with your EC2 connection are not authorized to access the AMI. Perhaps it was created with a different account?
Upvotes: 1
Reputation: 795
You should be able to connect with your key and ID only, so without specifying the region:
from boto.ec2.connection import EC2Connection
connection = EC2Connection(<S3_ACCESSKEYID>, <S3_SECRETACCESSKEY>)
print connection
gives me:
EC2Connection:ec2.us-east-1.amazonaws.com
Hope that helps.
Upvotes: 0