From 50e53e8b203d0db47222cd7691fc048fb5974652 Mon Sep 17 00:00:00 2001 From: Scott Piper Date: Thu, 4 Nov 2021 09:22:06 -0600 Subject: [PATCH] Bug fixes in amis command --- commands/amis.py | 14 +++++++++++--- commands/collect.py | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/commands/amis.py b/commands/amis.py index 457b8c771..72ca188ae 100644 --- a/commands/amis.py +++ b/commands/amis.py @@ -60,16 +60,16 @@ def amis(args, accounts, config): ) ) - for region in listdir("data/aws/"): + for region_name in listdir("data/aws/"): # Get public images - public_images_file = "data/aws/{}/ec2-describe-images.json".format(region) + public_images_file = "data/aws/{}/ec2-describe-images.json".format(region_name) public_images = json.load(open(public_images_file)) resource_filter = ".Images[]" public_images = pyjq.all(resource_filter, public_images) for account in accounts: account = Account(None, account) - region = Region(account, {"RegionName": region}) + region = Region(account, {"RegionName": region_name}) instances = query_aws(account, "ec2-describe-instances", region) resource_filter = ( @@ -77,10 +77,18 @@ def amis(args, accounts, config): ) if args.instance_filter != "": resource_filter += "|{}".format(args.instance_filter) + + if 'Reservations' not in instances: + print(f"** skipping: {account.name} in {region_name}") + continue + instances = pyjq.all(resource_filter, instances) account_images = query_aws(account, "ec2-describe-images", region) resource_filter = ".Images[]" + if 'Images' not in account_images: + print(f"** skipping: {account.name} in {region_name}") + continue account_images = pyjq.all(resource_filter, account_images) for instance in instances: diff --git a/commands/collect.py b/commands/collect.py index 9c330d6c2..5376824df 100644 --- a/commands/collect.py +++ b/commands/collect.py @@ -307,6 +307,7 @@ def collect(arguments): # Services that will only be queried in the default_ # TODO: Identify these from boto universal_services = [ + "account", "sts", "iam", "route53",