How to use describe_key_pairs method in localstack

Best Python code snippet using localstack_python

keypairs.py

Source:keypairs.py Github

copy

Full Screen

...12 self.ec2_client = boto3.client("ec2")13 def list_keypairs(14 self,15 ):16 json_results = self.ec2_client.describe_key_pairs()17 return json_results18 def get_keypair_by_name(self, name):19 json_results = self.ec2_client.describe_key_pairs(20 Filters=[21 {"Name": "key-name", "Values": [name]},22 ]23 )24 return json_results25 def get_keypair_by_id(self, keypairid):26 json_results = self.ec2_client.describe_key_pairs(27 Filters=[28 {"Name": "key-pair-id", "Values": [keypairid]},29 ]30 )31 return json_results32 def get_keypair_by_fingerprint(self, fingerprint):33 json_results = self.ec2_client.describe_key_pairs(34 Filters=[35 {"Name": "fingerprint", "Values": [fingerprint]},36 ]37 )38 return json_results39 def get_keypair_by_tag_keyname(self, tagkeyname):40 json_results = self.ec2_client.describe_key_pairs(41 Filters=[42 {"Name": "tag-key", "Values": [tagkeyname]},43 ]44 )45 return json_results46 def get_keypair_by_tag(self, key, value):47 NameValue = f"tag:{key}"48 json_results = self.ec2_client.describe_key_pairs(49 Filters=[50 {"Name": NameValue, "Values": [value]},51 ]52 )53 return json_results54 def import_keypair(self, name, publickey_string, tag_specification=None):55 publickeymaterial = publickey_string.encode("utf-8")56 if tag_specification != None:57 json_results = self.ec2_client.import_key_pair(58 KeyName=name,59 PublicKeyMaterial=publickeymaterial,60 TagSpecifications=tag_specification,61 )62 else:...

Full Screen

Full Screen

key_pair.py

Source:key_pair.py Github

copy

Full Screen

...15 fname = os.path.join(key_dir, '{}.pem'.format(key_name))16 with open(fname, 'w') as f:17 f.write(key['KeyMaterial'])18 return key19def describe_key_pairs():20 """21 Returns all key pairs for region22 """23 region_keys = {}24 for r in boto3.client('ec2', 'us-west-2').describe_regions()['Regions']:25 region = r['RegionName']26 client = boto3.client('ec2', region_name=region)27 try:28 pairs = client.describe_key_pairs()29 if pairs:30 region_keys[region] = pairs31 except Exception as e:32 app.logger.info(e)33 return region_keys34def run(dapp, cmd):35 global app36 app = dapp37 def cmd_describe_key_pairs():38 t = PrettyTable([39 'KeyName', 'KeyFingerprint', 'Region'40 ])41 for region, keys in describe_key_pairs().items():42 for pair in keys['KeyPairs']:43 t.add_row([pair['KeyName'], pair['KeyFingerprint'], region])44 print(t)45 def cmd_create_key_pair():46 parser = argparse.ArgumentParser()47 parser.add_argument(48 '--region', required=True, help='AWS Region')49 parser.add_argument('--key_name', required=True)50 parser.add_argument(51 '--key_dir', required=False, default='~/.ssh',52 help='Directory where key will be stored')53 args, extra_params = parser.parse_known_args()54 pair = create_key_pair(55 args.key_name, key_dir=args.key_dir, region=args.region)...

Full Screen

Full Screen

ec2_key_pair.py

Source:ec2_key_pair.py Github

copy

Full Screen

2import boto33#Describe the existing key pairs4print ("Showing the existing key pairs")5ec2 = boto3.client('ec2')6response = ec2.describe_key_pairs()7print (response)8#Creating new key pairs9ec2 = boto3.client('ec2')10response = ec2.create_key_pair(KeyName = 'boto-key-pair')11#Describe the existing key pairs12print ("Showing the existing key pairs")13ec2 = boto3.client('ec2')14response = ec2.describe_key_pairs()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful