Skip to content

Commit

Permalink
Merge pull request #901 from 0xdabbad00/bug_fixes
Browse files Browse the repository at this point in the history
Bug fixes in amis command
  • Loading branch information
0xdabbad00 authored Nov 4, 2021
2 parents b484027 + 50e53e8 commit 652cb3b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions commands/amis.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,35 @@ 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 = (
'.Reservations[].Instances[] | select(.State.Name == "running")'
)
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:
Expand Down
1 change: 1 addition & 0 deletions commands/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 652cb3b

Please sign in to comment.