Created
August 11, 2022 14:43
-
-
Save phwelo/6d4c267a51eb145e7ee9bd0836e2cdab to your computer and use it in GitHub Desktop.
Revisions
-
phwelo created this gist
Aug 11, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ #!/usr/bin/env python3 import boto3 import json client = boto3.client('ec2') ec2_result = client.describe_instances() results = [] for result in ec2_result["Reservations"]: for instance in result["Instances"]: obj = { "id": instance["InstanceId"], "state": instance["State"]["Name"], "subnet": instance["SubnetId"], "vpc_id": instance["VpcId"] } try: obj["public_ip"] = instance["PublicIpAddress"] except KeyError: continue if "public_ip" in obj and obj["state"] == "running": results.append(obj) print(json.dumps(results))%