AWS SDK Version 3 for .NET
API Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Creates a Spot Fleet request.

The Spot Fleet request specifies the total target capacity and the On-Demand target capacity. Amazon EC2 calculates the difference between the total capacity and On-Demand capacity, and launches the difference as Spot capacity.

You can submit a single request that includes multiple launch specifications that vary by instance type, AMI, Availability Zone, or subnet.

By default, the Spot Fleet requests Spot Instances in the Spot Instance pool where the price per unit is the lowest. Each launch specification can include its own instance weighting that reflects the value of the instance type to your application workload.

Alternatively, you can specify that the Spot Fleet distribute the target capacity across the Spot pools included in its launch specifications. By ensuring that the Spot Instances in your Spot Fleet are in different Spot pools, you can improve the availability of your fleet.

You can specify tags for the Spot Fleet request and instances launched by the fleet. You cannot tag other resource types in a Spot Fleet request because only the spot-fleet-request and instance resource types are supported.

For more information, see Spot Fleet requests in the Amazon EC2 User Guide.

We strongly discourage using the RequestSpotFleet 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.

Note:

For .NET Core this operation is only available in asynchronous form. Please refer to RequestSpotFleetAsync.

Namespace: Amazon.EC2
Assembly: AWSSDK.EC2.dll
Version: 3.x.y.z

Syntax

C#
public virtual RequestSpotFleetResponse RequestSpotFleet(
         RequestSpotFleetRequest request
)

Parameters

request
Type: Amazon.EC2.Model.RequestSpotFleetRequest

Container for the necessary parameters to execute the RequestSpotFleet service method.

Return Value


The response from the RequestSpotFleet service method, as returned by EC2.

Examples

This example creates a Spot fleet request with two launch specifications that differ only by subnet. The Spot fleet launches the instances in the specified subnet with the lowest price. If the instances are launched in a default VPC, they receive a public IP address by default. If the instances are launched in a nondefault VPC, they do not receive a public IP address by default. Note that you can't specify different subnets from the same Availability Zone in a Spot fleet request.

To request a Spot fleet in the subnet with the lowest price


var client = new AmazonEC2Client();
var response = client.RequestSpotFleet(new RequestSpotFleetRequest 
{
    SpotFleetRequestConfig = new SpotFleetRequestConfigData {
        IamFleetRole = "arn:aws:iam::123456789012:role/my-spot-fleet-role",
        LaunchSpecifications = new List<SpotFleetLaunchSpecification> {
            new SpotFleetLaunchSpecification {
                IamInstanceProfile = new IamInstanceProfileSpecification { Arn = "arn:aws:iam::123456789012:instance-profile/my-iam-role" },
                ImageId = "ami-1a2b3c4d",
                InstanceType = "m3.medium",
                KeyName = "my-key-pair",
                SecurityGroups = new List<GroupIdentifier> {
                    new GroupIdentifier { GroupId = "sg-1a2b3c4d" }
                },
                SubnetId = "subnet-1a2b3c4d, subnet-3c4d5e6f"
            }
        },
        SpotPrice = "0.04",
        TargetCapacity = 2
    }
});

string spotFleetRequestId = response.SpotFleetRequestId;

            

This example creates a Spot fleet request with two launch specifications that differ only by Availability Zone. The Spot fleet launches the instances in the specified Availability Zone with the lowest price. If your account supports EC2-VPC only, Amazon EC2 launches the Spot instances in the default subnet of the Availability Zone.

To request a Spot fleet in the Availability Zone with the lowest price


var client = new AmazonEC2Client();
var response = client.RequestSpotFleet(new RequestSpotFleetRequest 
{
    SpotFleetRequestConfig = new SpotFleetRequestConfigData {
        IamFleetRole = "arn:aws:iam::123456789012:role/my-spot-fleet-role",
        LaunchSpecifications = new List<SpotFleetLaunchSpecification> {
            new SpotFleetLaunchSpecification {
                IamInstanceProfile = new IamInstanceProfileSpecification { Arn = "arn:aws:iam::123456789012:instance-profile/my-iam-role" },
                ImageId = "ami-1a2b3c4d",
                InstanceType = "m3.medium",
                KeyName = "my-key-pair",
                Placement = new SpotPlacement { AvailabilityZone = "us-west-2a, us-west-2b" },
                SecurityGroups = new List<GroupIdentifier> {
                    new GroupIdentifier { GroupId = "sg-1a2b3c4d" }
                }
            }
        },
        SpotPrice = "0.04",
        TargetCapacity = 2
    }
});

string spotFleetRequestId = response.SpotFleetRequestId;

            

This example assigns public addresses to instances launched in a nondefault VPC. Note that when you specify a network interface, you must include the subnet ID and security group ID using the network interface.

To launch Spot instances in a subnet and assign them public IP addresses


var client = new AmazonEC2Client();
var response = client.RequestSpotFleet(new RequestSpotFleetRequest 
{
    SpotFleetRequestConfig = new SpotFleetRequestConfigData {
        IamFleetRole = "arn:aws:iam::123456789012:role/my-spot-fleet-role",
        LaunchSpecifications = new List<SpotFleetLaunchSpecification> {
            new SpotFleetLaunchSpecification {
                IamInstanceProfile = new IamInstanceProfileSpecification { Arn = "arn:aws:iam::880185128111:instance-profile/my-iam-role" },
                ImageId = "ami-1a2b3c4d",
                InstanceType = "m3.medium",
                KeyName = "my-key-pair",
                NetworkInterfaces = new List<InstanceNetworkInterfaceSpecification> {
                    new InstanceNetworkInterfaceSpecification {
                        AssociatePublicIpAddress = true,
                        DeviceIndex = 0,
                        Groups = new List<string> {
                            "sg-1a2b3c4d"
                        },
                        SubnetId = "subnet-1a2b3c4d"
                    }
                }
            }
        },
        SpotPrice = "0.04",
        TargetCapacity = 2
    }
});

string spotFleetRequestId = response.SpotFleetRequestId;

            

This example creates a Spot fleet request that launches 30 instances using the diversified allocation strategy. The launch specifications differ by instance type. The Spot fleet distributes the instances across the launch specifications such that there are 10 instances of each type.

To request a Spot fleet using the diversified allocation strategy


var client = new AmazonEC2Client();
var response = client.RequestSpotFleet(new RequestSpotFleetRequest 
{
    SpotFleetRequestConfig = new SpotFleetRequestConfigData {
        AllocationStrategy = "diversified",
        IamFleetRole = "arn:aws:iam::123456789012:role/my-spot-fleet-role",
        LaunchSpecifications = new List<SpotFleetLaunchSpecification> {
            new SpotFleetLaunchSpecification {
                ImageId = "ami-1a2b3c4d",
                InstanceType = "c4.2xlarge",
                SubnetId = "subnet-1a2b3c4d"
            },
            new SpotFleetLaunchSpecification {
                ImageId = "ami-1a2b3c4d",
                InstanceType = "m3.2xlarge",
                SubnetId = "subnet-1a2b3c4d"
            },
            new SpotFleetLaunchSpecification {
                ImageId = "ami-1a2b3c4d",
                InstanceType = "r3.2xlarge",
                SubnetId = "subnet-1a2b3c4d"
            }
        },
        SpotPrice = "0.70",
        TargetCapacity = 30
    }
});

string spotFleetRequestId = response.SpotFleetRequestId;

            

Version Information

.NET Framework:
Supported in: 4.5, 4.0, 3.5

See Also