EC2¶
Utilities for working with Amazon EC2.
describe_availability_zones ¶
describe_availability_zones(
regions=None, all_regions=False
)
Describe availability zones
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
regions
|
Optional[List[str]]
|
Return AZs for regions if specified. Defaults to None. |
None
|
all_regions
|
bool
|
Whether to return for all regions (if no regions specified). Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
List[AvailabilityZoneTypeDef]
|
List of availability zone info |
Source code in src/aibs_informatics_aws_utils/ec2.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
describe_instance_type_offerings ¶
describe_instance_type_offerings(
instance_types=None,
regions=None,
availability_zones=None,
)
Describe instance type offerings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance_types
|
Optional[List[str]]
|
deprecated. Is not supported. Defaults to None. |
None
|
regions
|
Optional[List[str]]
|
Optional subset of regions. Defaults to None. |
None
|
availability_zones
|
Optional[List[str]]
|
Optional subset of availability zones. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
List[InstanceTypeOfferingTypeDef]
|
List of instance type offerings |
Source code in src/aibs_informatics_aws_utils/ec2.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
describe_instance_types ¶
describe_instance_types(instance_types=None, filters=None)
Describe instance types
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance_types
|
Optional[List[str]]
|
subset of instance types. Defaults to None. |
None
|
filters
|
Optional[Dict[str, List[str]]]
|
Filters to apply. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
List[InstanceTypeInfoTypeDef]
|
List of instance type details |
Source code in src/aibs_informatics_aws_utils/ec2.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
describe_instance_types_by_props ¶
describe_instance_types_by_props(
architectures=None,
vcpu_limits=None,
memory_limits=None,
gpu_limits=None,
on_demand_support=None,
spot_support=None,
regions=None,
availability_zones=None,
)
Describe instance types by properties of those instance types
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
architectures
|
Optional[List["arm64", "i386", "x86_64"]]]
|
Filter by architecture. Defaults to None. |
None
|
vcpu_limits
|
Optional[RawRange]
|
vCPU range constraints. Can be a single number, a tuple of numbers, or None. Defaults to None. |
None
|
memory_limits
|
Optional[RawRange]
|
memory range constraints. Can be a single number, a tuple of numbers, or None. Defaults to None. |
None
|
gpu_limits
|
Optional[RawRange]
|
GPU range constraints. Can be a single number, a tuple of numbers, or None. Defaults to None. |
None
|
on_demand_support
|
Optional[bool]
|
filter based on on-demand support. |
None
|
spot_support
|
Optional[bool]
|
Filter based on spot support. Defaults to None. |
None
|
regions
|
Optional[List[str]]
|
Filter based on availability in regions. Defaults to None. |
None
|
availability_zones
|
Optional[List[str]]
|
Filter based on availability in availability zones. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
List[InstanceTypeInfoTypeDef]
|
List of instance type details matching the specified filters |
Source code in src/aibs_informatics_aws_utils/ec2.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | |
describe_regions ¶
describe_regions()
Describe all enabled AWS regions.
Returns:
| Type | Description |
|---|---|
|
List of region information dictionaries. |
Source code in src/aibs_informatics_aws_utils/ec2.py
207 208 209 210 211 212 213 214 | |
get_availability_zones ¶
get_availability_zones(regions=None, all_regions=False)
Gets a list of availability zones
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
regions
|
Optional[List[str]]
|
Return AZs for regions if specified. Defaults to None. |
None
|
all_regions
|
bool
|
Whether to return for all regions (if no regions specified). Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List of availability zones |
Source code in src/aibs_informatics_aws_utils/ec2.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
get_common_instance_types ¶
get_common_instance_types(
regions=None, availability_zones=None
)
Get the common instance types across a list of regions or availability zones
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
regions
|
Optional[List[str]]
|
Optionally filter based on regions. Defaults to None. (uses current region if azs not specified) |
None
|
availability_zones
|
Optional[List[str]]
|
Filter based on availability zone. Defaults to None. If not specified, all availability zones in the specified regions are used. |
None
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List of instance types common across the specified regions or availability zones |
Source code in src/aibs_informatics_aws_utils/ec2.py
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | |
get_instance_type_on_demand_price ¶
get_instance_type_on_demand_price(region, instance_type)
Get the on demand Linux price for an instance type in a region
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region
|
str
|
The region to get the price for |
required |
instance_type
|
str
|
The instance type to get the price for |
required |
Returns:
| Type | Description |
|---|---|
float
|
price in USD per hour for Linux on demand instance |
Source code in src/aibs_informatics_aws_utils/ec2.py
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 | |
get_instance_type_spot_price ¶
get_instance_type_spot_price(
region, instance_type, product_description="Linux/UNIX"
)
Get the latest spot price for an instance type
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region
|
str
|
The region to get the price for |
required |
instance_type
|
str
|
The instance type to get the price for |
required |
product_description
|
str
|
Defaults to "Linux/UNIX". |
'Linux/UNIX'
|
Returns:
| Type | Description |
|---|---|
float
|
price in USD per hour for Linux spot instance |
Source code in src/aibs_informatics_aws_utils/ec2.py
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | |
get_instance_types_by_az ¶
get_instance_types_by_az(
regions=None, availability_zones=None
)
Get the instance types available in each availability zone
Results are combined regions and availability zones. If neither is specified, the current region's AZs are used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
regions
|
Optional[List[str]]
|
Specify zones by region. If no region or az specified, current region is used. |
None
|
availability_zones
|
Optional[List[str]]
|
Specify by az. If not specified, all availability zones in the specified regions are used. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, List[str]]
|
Dict[str, List[str]]: Mapping of availability zone to list of available instance types |
Source code in src/aibs_informatics_aws_utils/ec2.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | |
get_instance_types_spot_price ¶
get_instance_types_spot_price(
region,
instance_types=None,
product_descriptions=("Linux/UNIX",),
)
Get the current spot price for a list of instance types
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region
|
str
|
The region to get spot price for |
required |
instance_types
|
Optional[List[str]]
|
optional list of instance types. If not specified, all instance types in that region with spot prices are returned. |
None
|
product_descriptions
|
Optional[Sequence[str]]
|
Defaults to ("Linux/UNIX",). |
('Linux/UNIX',)
|
Returns:
| Type | Description |
|---|---|
Dict[InstanceTypeType, float]
|
Dict[str, float]: Mapping of instance type to spot price in USD |
Source code in src/aibs_informatics_aws_utils/ec2.py
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 | |
get_regions ¶
get_regions()
Gets all available regions
Returns:
| Type | Description |
|---|---|
List[str]
|
List of regions |
Source code in src/aibs_informatics_aws_utils/ec2.py
217 218 219 220 221 222 223 224 225 226 227 | |
instance_type_sort_key ¶
instance_type_sort_key(instance_type)
Converts Instance Type into sort key (family, size rank, factor)
Size Rank
- nano
- micro
- small
- medium
- large
- metal
Examples:
- c5.2xlarge -> ('c5', 4, 2)
- m7i-flex.metal -> ('m7i-flex', 5, 0)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance_type
|
str
|
The instance type to split |
required |
Returns:
| Type | Description |
|---|---|
Tuple[str, int, int]
|
Tuple[str, int, int]: The instance type components (family, size rank, factor) |
Source code in src/aibs_informatics_aws_utils/ec2.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
network_performance_sort_key ¶
network_performance_sort_key(network_performance)
Converts network performance description into a numerical sort key
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network_performance
|
str
|
The network performance description e.g. "Low", "Moderate", "High", "Up to 10 Gigabit", "25 Gigabit", etc. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The upper limit network performance value in Gbps |
Source code in src/aibs_informatics_aws_utils/ec2.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
normalize_range ¶
normalize_range(
raw_range,
min_limit=None,
max_limit=None,
raise_on_invalid=True,
treat_single_value_as_max=False,
num_type=int,
)
Normalize a range of numbers to a tuple of (lower_limit, upper_limit)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_range
|
N | [N | None, N | None] | None
|
The raw range to normalize. This can be a single number, a tuple of numbers, or None. |
required |
max_limit
|
Optional[N]
|
Restricts max end of range, if specified. Defaults to None. |
None
|
min_limit
|
Optional[N]
|
Restricts min end of range, if specified. Defaults to None. |
None
|
raise_on_invalid
|
bool
|
Raise an error if the range is invalid. If not, range is modified to match the max requirements. Defaults to True. |
True
|
treat_single_value_as_max
|
bool
|
If True, a single number is treated as the max end of the range. Defaults to False. |
False
|
num_type
|
Type[N]
|
the data type to use. Defaults to int. |
int
|
Returns:
| Type | Description |
|---|---|
Tuple[Optional[N], Optional[N]]
|
Tuple[Optional[N], Optional[N]]: The normalized range |
Source code in src/aibs_informatics_aws_utils/ec2.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |