I tried below code to list all AWS services in my account per region using the below code
import boto3
session = boto3.Session()
regions = session.get_available_regions("ssm")
d = {}
for region in regions:
s = boto3.Session(region_name=region)
d[region] = s.get_available_services()
print(d)
But I think that the next part to this code is the triky part, now what I need to do is go through each service in each region and check if any of them was spun up, but it ain't easy as we need to create an object for a particular service then need to know which method to apply to find whether it is used or not and there are more than 300 services in each region.
Here is an example for ec2. Need to find similar functions for every service which is not possible
ec2client = boto3.client('ec2', region_name="ap-south-1")
instanceresponse = ec2client.describe_instances()
for reservation in instanceresponse["Reservations"]:
for instance in reservation["Instances"]:
print(instance["InstanceId"])
Can someone suggest me any alternate option to optimize my code?