request_spot_instances
async
¶
request_spot_instances(
*,
config_overrides: Optional[AsyncEC2ClientConfig] = None,
launch_specification: Optional[RequestSpotLaunchSpecification] = None,
tag_specifications: Optional[TagSpecificationList] = None,
instance_interruption_behavior: Optional[InstanceInterruptionBehavior] = None,
dry_run: Optional[Boolean] = None,
spot_price: Optional[String] = None,
client_token: Optional[String] = None,
instance_count: Optional[Integer] = None,
type: Optional[SpotInstanceType] = None,
valid_from: Optional[DateTime] = None,
valid_until: Optional[DateTime] = None,
launch_group: Optional[String] = None,
availability_zone_group: Optional[String] = None,
block_duration_minutes: Optional[Integer] = None,
) -> RequestSpotInstancesResult
Creates a Spot Instance request.
For more information, see Work with Spot Instance in the Amazon EC2 User Guide.
We strongly discourage using the RequestSpotInstances API because it is a legacy API with no planned investment. For options for requesting Spot Instances, see Which is the best Spot request method to use? in the Amazon EC2 User Guide.
Parameters:
-
launch_specification(Optional[RequestSpotLaunchSpecification], default:None) –The launch specification.
-
tag_specifications(Optional[TagSpecificationList], default:None) –The key-value pair for tagging the Spot Instance request on creation. The value for
ResourceTypemust bespot-instances-request, otherwise the Spot Instance request fails. To tag the Spot Instance request after it has been created, see CreateTags. -
instance_interruption_behavior(Optional[InstanceInterruptionBehavior], default:None) –The behavior when a Spot Instance is interrupted. The default is
terminate. -
dry_run(Optional[Boolean], default:None) –Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is
DryRunOperation. Otherwise, it isUnauthorizedOperation. -
spot_price(Optional[String], default:None) –The maximum price per unit hour that you are willing to pay for a Spot Instance. We do not recommend using this parameter because it can lead to increased interruptions. If you do not specify this parameter, you will pay the current Spot price.
If you specify a maximum price, your instances will be interrupted more frequently than if you do not specify this parameter.
-
client_token(Optional[String], default:None) –Unique, case-sensitive identifier that you provide to ensure the idempotency of the request. For more information, see Ensuring idempotency in Amazon EC2 API requests in the Amazon EC2 User Guide.
-
instance_count(Optional[Integer], default:None) –The maximum number of Spot Instances to launch.
Default: 1
-
type(Optional[SpotInstanceType], default:None) –The Spot Instance request type.
Default:
one-time -
valid_from(Optional[DateTime], default:None) –The start date of the request. If this is a one-time request, the request becomes active at this date and time and remains active until all instances launch, the request expires, or the request is canceled. If the request is persistent, the request becomes active at this date and time and remains active until it expires or is canceled.
The specified start date and time cannot be equal to the current date and time. You must specify a start date and time that occurs after the current date and time.
-
valid_until(Optional[DateTime], default:None) –The end date of the request, in UTC format (YYYY-MM-DDTHH:MM:SSZ).
-
For a persistent request, the request remains active until the
ValidUntildate and time is reached. Otherwise, the request remains active until you cancel it. -
For a one-time request, the request remains active until all instances launch, the request is canceled, or the
ValidUntildate and time is reached. By default, the request is valid for 7 days from the date the request was created.
-
-
launch_group(Optional[String], default:None) –The instance launch group. Launch groups are Spot Instances that launch together and terminate together.
Default: Instances are launched and terminated individually
-
availability_zone_group(Optional[String], default:None) –The user-specified name for a logical grouping of requests.
When you specify an Availability Zone group in a Spot Instance request, all Spot Instances in the request are launched in the same Availability Zone. Instance proximity is maintained with this parameter, but the choice of Availability Zone is not. The group applies only to requests for Spot Instances of the same instance type. Any additional Spot Instance requests that are specified with the same Availability Zone group name are launched in that same Availability Zone, as long as at least one instance from the group is still active.
If there is no active instance running in the Availability Zone group that you specify for a new Spot Instance request (all instances are terminated, the request is expired, or the maximum price you specified falls below current Spot price), then Amazon EC2 launches the instance in any Availability Zone where the constraint can be met. Consequently, the subsequent set of Spot Instances could be placed in a different zone from the original request, even if you specified the same Availability Zone group.
Default: Instances are launched in any available Availability Zone.
-
block_duration_minutes(Optional[Integer], default:None) –Deprecated.
Raises:
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
To create a one-time Spot Instance request This example creates a one-time Spot Instance request for five instances in the specified Availability Zone. If your account supports EC2-VPC only, Amazon EC2 launches the instances in the default subnet of the specified Availability Zone.
>>> await client.request_spot_instances(spot_price='0.03', instance_count=5, type='one-time', launch_specification={'ImageId': 'ami-1a2b3c4d', 'KeyName': 'my-key-pair', 'SecurityGroupIds': ['sg-1a2b3c4d'], 'InstanceType': 'm3.medium', 'Placement': {'AvailabilityZone': 'us-west-2a'}, 'IamInstanceProfile': {'Arn': 'arn:aws:iam::123456789012:instance-profile/my-iam-role'}})
To create a one-time Spot Instance request
This example command creates a one-time Spot Instance request for five instances in the specified subnet. Amazon EC2 launches the instances in the specified subnet. If the VPC is a nondefault VPC, the instances do not receive a public IP address by default.
>>> await client.request_spot_instances(spot_price='0.050', instance_count=5, type='one-time', launch_specification={'ImageId': 'ami-1a2b3c4d', 'SecurityGroupIds': ['sg-1a2b3c4d'], 'InstanceType': 'm3.medium', 'SubnetId': 'subnet-1a2b3c4d', 'IamInstanceProfile': {'Arn': 'arn:aws:iam::123456789012:instance-profile/my-iam-role'}})
Source code in docs_src/capo_ec2/_services/async_ec2.py
58413 58414 58415 58416 58417 58418 58419 58420 58421 58422 58423 58424 58425 58426 58427 58428 58429 58430 58431 58432 58433 58434 58435 58436 58437 58438 58439 58440 58441 58442 58443 58444 58445 58446 58447 58448 58449 58450 58451 58452 58453 58454 58455 58456 58457 58458 58459 58460 58461 58462 58463 58464 58465 58466 58467 58468 58469 58470 58471 58472 58473 58474 58475 58476 58477 58478 58479 58480 58481 58482 58483 58484 58485 58486 58487 58488 58489 58490 58491 58492 58493 58494 58495 58496 58497 58498 58499 58500 58501 58502 58503 58504 58505 58506 58507 58508 58509 58510 58511 58512 58513 58514 58515 58516 58517 58518 58519 58520 58521 58522 58523 58524 58525 58526 58527 58528 58529 58530 58531 58532 58533 58534 58535 58536 58537 58538 58539 58540 58541 | |