import boto3
import logging
import traceback
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger("test")
aki=" ... my access key id .... "
sak="... my secure access key ...."
client = boto3.client('ec2',region_name='us-west-2',aws_access_key_id=aki, aws_secret_access_key=sak)
def create_keypair(client, KeyName):
try:
res = client.create_key_pair(KeyName=KeyName)
print res['KeyName']
print res['KeyFingerprint']
print res['KeyMaterial']
except:
traceback.print_exc()
def describe_keypairs(client, KeyName):
try:
res = client.describe_key_pairs(KeyNames=[KeyName])
if res.has_key('KeyPairs') and len(res['KeyPairs']) > 0:
logger.debug("# of Keypairs:%d" % len(res['KeyPairs']))
logger.debug("Found %s" % KeyName)
except:
traceback.print_exc()
create_keypair(client, "user2")
describe_keypairs(client, "user2")
describe_keypairs(client, "not_found_user")