requestSpotInstances

abstract suspend fun requestSpotInstances(input: RequestSpotInstancesRequest = RequestSpotInstancesRequest { }): RequestSpotInstancesResponse

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.

Samples

// 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.
ec2Client.requestSpotInstances {
    spotPrice = "0.03"
    instanceCount = 5
    type = SpotInstanceType.fromValue("one-time")
    launchSpecification = RequestSpotLaunchSpecification {
        imageId = "ami-1a2b3c4d"
        keyName = "my-key-pair"
        securityGroupIds = listOf<String>(
            "sg-1a2b3c4d"
        )
        instanceType = InstanceType.fromValue("m3.medium")
        placement = SpotPlacement {
            availabilityZone = "us-west-2a"
        }
        iamInstanceProfile = IamInstanceProfileSpecification {
            arn = "arn:aws:iam::123456789012:instance-profile/my-iam-role"
        }
    }
}
// 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.
ec2Client.requestSpotInstances {
    spotPrice = "0.050"
    instanceCount = 5
    type = SpotInstanceType.fromValue("one-time")
    launchSpecification = RequestSpotLaunchSpecification {
        imageId = "ami-1a2b3c4d"
        securityGroupIds = listOf<String>(
            "sg-1a2b3c4d"
        )
        instanceType = InstanceType.fromValue("m3.medium")
        subnetId = "subnet-1a2b3c4d"
        iamInstanceProfile = IamInstanceProfileSpecification {
            arn = "arn:aws:iam::123456789012:instance-profile/my-iam-role"
        }
    }
}