request_spot_instances
¶
request_spot_instances(
*,
config_overrides: Optional[EC2ClientConfig] = 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.
>>> 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.
>>> 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/ec2.py
57608 57609 57610 57611 57612 57613 57614 57615 57616 57617 57618 57619 57620 57621 57622 57623 57624 57625 57626 57627 57628 57629 57630 57631 57632 57633 57634 57635 57636 57637 57638 57639 57640 57641 57642 57643 57644 57645 57646 57647 57648 57649 57650 57651 57652 57653 57654 57655 57656 57657 57658 57659 57660 57661 57662 57663 57664 57665 57666 57667 57668 57669 57670 57671 57672 57673 57674 57675 57676 57677 57678 57679 57680 57681 57682 57683 57684 57685 57686 57687 57688 57689 57690 57691 57692 57693 57694 57695 57696 57697 57698 57699 57700 57701 57702 57703 57704 57705 57706 57707 57708 57709 57710 57711 57712 57713 57714 57715 57716 57717 57718 57719 57720 57721 57722 57723 57724 57725 57726 57727 57728 57729 57730 57731 57732 57733 57734 57735 | |