-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhelper.py
67 lines (47 loc) · 1.55 KB
/
helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! /usr/bin/env python3
import boto3
import config
def get_all_instances(region_list=None):
if not region_list:
region_list = config.REGIONS
instances = []
for region in region_list:
client = boto3.client("ec2", region_name=region)
data = client.describe_instances()
for res in data["Reservations"]:
instances.extend(res["Instances"])
return instances
def get_all_rds(region=None):
if not region:
region = config.REGIONS
databases = []
for region in config.REGIONS:
client = boto3.client("rds", region_name=region)
data = client.describe_db_instances()
databases.extend(data["DBInstances"])
return databases
def get_all_sg(region=None):
if not region:
region = config.REGIONS
groups = []
for region in config.REGIONS:
client = boto3.client("ec2", region_name=region)
data = client.describe_security_groups()
groups.extend(data["SecurityGroups"])
return groups
def get_all_volumes(region=None):
if not region:
region = config.REGIONS
volumes = []
for region in config.REGIONS:
client = boto3.client("ec2", region_name=region)
data = client.describe_volumes()
volumes.extend(data["Volumes"])
return volumes
def get_account_id():
return boto3.client("sts").get_caller_identity().get("Account")
def get_all_regions():
ec2 = boto3.client("ec2")
response = ec2.describe_regions()
regions = response["Regions"]
return [r["RegionName"] for r in regions]