in source/idea/idea-sdk/src/ideasdk/aws/aws_util.py [0:0]
def get_instance_type_class(instance_type: str) -> Tuple[str, bool]:
"""
given an instance type, return it's instance class
refer: https://aws.amazon.com/ec2/instance-types/
implementation notes:
> it's not really necessary to keep this mapping updated as just a basic check
of startswith( 1st character of instance type) should do the job.
> there are certain exceptions:
- Trn: starts with trn and can conflict with (T)
since we check (Trn) instance before (T), this case will not occur.
- Inf: starts with inf and can conflict with (I)
since we check (Inf) instance before (I), this case will not occur.
- DL: starts with dl and can conflict with (D)
since we check (DL) instance before (D), this case will not occur.
- HighMem: starts with u-
!! if AWS adds new instance type starting with u-, this implementation
needs to be revisited.
- mac: starts with mac and can conflict with (M)
since we check mac instance before m instances, this case will not occur.
- hpc: starts with h and can conflict with (H)
since we check (hpc) instance before (H), this case will not occur.
:returns a tuple:
> [0] = instance class (A, C, D.. )
> [1] = True if standard, False if non-standard
"""
family = instance_type.split('.')[0].lower()
# accelerated computing
if family.startswith(('p4de', 'p4d', 'p3dn', 'p3', 'p2', 'p')):
return 'P', False
elif family.startswith(('dl1', 'dl')):
return 'DL', False # todo - verify instance class in quota
elif family.startswith(('inf1', 'inf')):
return 'Inf', False
elif family.startswith(('trn1', 'trn')):
return 'Trn', False
elif family.startswith(('g6', 'gr6', 'g4dn', 'g4ad', 'g5', 'g5g', 'g3s', 'g3', 'g2', 'g')):
return 'G', False
elif family.startswith(('f1', 'f')):
return 'F', False
elif family.startswith(('vt1', 'vt')):
return 'VT', False
# storage optimized
elif family.startswith(('i4i', 'i3', 'i3en', 'i')): # standard
return 'I', True
elif family.startswith('lm4gn'):
return 'lm4gn', True
elif family.startswith('ls4gen'):
return 'ls4gen', True
elif family.startswith(('d2', 'd3', 'd3en', 'd')): # standard
return 'D', True
elif family.startswith(('hpc6a', 'hpc')):
return 'HPC', False
elif family.startswith(('h1', 'h')): # standard
return 'H', False
# memory optimized
elif family.startswith(('r6a', 'r6g', 'r6i', 'r5a', 'r5b', 'r5d', 'r5dn', 'r5ad', 'r5n', 'r6', 'r5', 'r4', 'r')): # standard
return 'R', True
elif family.startswith(('x2gd', 'x2idn', 'x2iedn', 'x2iezn', 'x1e', 'x1', 'x')):
return 'X', False
elif family.startswith('u-'):
return 'HighMem', False
elif family.startswith(('z1d', 'z')): # standard
return 'Z', True
# compute optimized
elif family.startswith(('c7g', 'c6g', 'c6gn', 'c6i', 'c5', 'c5a', 'c5n', 'c4', 'c')): # standard
return 'C', True
# general purpose
elif family.startswith(('mac1', 'mac2', 'mac')):
return 'mac', False
elif family.startswith(('t4g', 't3', 't3a', 't2', 't')): # standard
return 'T', True
elif family.startswith(('m6g', 'm6gd', 'm6i', 'm6id', 'm6a', 'm5', 'm5a', 'm5d', 'm5ad', 'm5dn', 'm5n', 'm5zn', 'm4', 'm')): # standard
return 'M', True
elif family.startswith(('a1', 'a')): # standard
return 'A', True