-
Notifications
You must be signed in to change notification settings - Fork 0
/
ec2.py
executable file
·56 lines (41 loc) · 1.52 KB
/
ec2.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Utility for EC2."""
import botocore
import boto3
import pprint
import sys
from typing import Dict
REGIONS = ["us-east-1", "us-east-2", "us-west-2"]
INSTANCES = ["c6in.32xlarge", "hpc6id.32xlarge", "hpc6a.48xlarge", "c7gn.16xlarge",
"r7iz.32xlarge", "c6gn.16xlarge", "hpc7g.16xlarge", "c6gn.16xlarge",
"trn1.32xlarge", "p4de.24xlarge", "g5.48xlarge", "u-24tb1.112xlarge"]
def describe_instance(instance: str) -> Dict:
"""Call boto3 to describe one instance."""
for region in REGIONS:
session = boto3.Session(region_name=region)
client = session.client('ec2')
try:
result = client.describe_instance_types(InstanceTypes=[instance])
return result
except botocore.exceptions.ClientError as error:
continue
print(f"{instance} not found")
return dict()
def print_instance(instance_type: str):
"""Print one instance."""
result = describe_instance(instance_type)
if result == dict():
return 1
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(result["InstanceTypes"][0]["InstanceType"])
pp.pprint(result["InstanceTypes"][0]["NetworkInfo"])
def main() -> int:
"""Invoke The main function."""
for instance_type in ["hpc6id.32xlarge", "hpc6a.48xlarge",
"c7gn.16xlarge", "hpc7g.16xlarge",
"r8g.48xlarge"]:
print_instance(instance_type)
return 0
if __name__ == '__main__':
sys.exit(main())