I was trying to create an EC2 key-pair using AWS Python SDK’s (Boto) create_key_pair() method, something like:
key_name = 'BlockChainEC2InstanceKeyPair-1' def create_new_key_pair(key_name): newKey = objEC2.create_key_pair(key_name) newKey.save(dir_to_save_new_key)
The keys are created as expected because I was able to fetch the keys using Boto’s get_all_key_pairs() method like below:
def get_all_keypairs(): try: key= objEC2.get_all_key_pairs() except: raise
The get_all_key_pairs() method returns the result like below showing that the key pair exists:
<DescribeKeyPairsResponse xmlns="http://ec2.amazonaws.com/doc/2014-10-01/"> <requestId>8d3faa7d-70c2-4b7c-ad18-810f23230c22</requestId> <keySet> <item> <keyName>BlockChainEC2InstanceKeyPair-1</keyName> <keyFingerprint>30:51:d4:19:a5:ba:11:dc:7e:9d:ca:49:10:01:30:34:b5:7e:9b:8a</keyFingerprint> </item> <item> <keyName>BlockChainEC2InstanceKeyPair-1.pem</keyName> <keyFingerprint>18:7e:ba:2c:44:67:44:a7:06:c4:68:3a:47:00:88:8f:31:98:27:e6</keyFingerprint> </item> </keySet> </DescribeKeyPairsResponse>
The problem was that when I logged onto my AWS console of the same account whose access keys I used to create the key pairs – I don’t get to see the newly created keys.
I posted this question to the ever helpful folks at Stack Overflow (here).
Based on the response I realized that Boto was creating the keys in its default configured region of US East while I was defaulting to US West when I log in to the AWS console. I was able to view the newly created keys when I changed the region in my AWS console [EC2 >> Key Pairs].
The fix was to add the following code snippet to the boto.cfg file:
[Boto] ec2_region_name = us-west-2