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.

Container for the parameters to the RequestSpotFleet operation. Creates a Spot fleet request.

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 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.

For more information, see Spot Fleet Requests in the Amazon Elastic Compute Cloud User Guide.

Inheritance Hierarchy

System.Object
  Amazon.Runtime.AmazonWebServiceRequest
    Amazon.EC2.AmazonEC2Request
      Amazon.EC2.Model.RequestSpotFleetRequest

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

Syntax

C#
public class RequestSpotFleetRequest : AmazonEC2Request
         IAmazonWebServiceRequest

The RequestSpotFleetRequest type exposes the following members

Constructors

NameDescription
Public Method RequestSpotFleetRequest()

Properties

NameTypeDescription
Public Property SpotFleetRequestConfig Amazon.EC2.Model.SpotFleetRequestConfigData

Gets and sets the property SpotFleetRequestConfig.

The configuration for the Spot fleet request.

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 response = client.RequestSpotFleet(new RequestSpotFleetRequest 
{
    SpotFleetRequestConfig = new SpotFleetRequestConfigData {
        IamFleetRole = "arn:aws:iam::123456789012:role/my-spot-fleet-role",
        LaunchSpecifications = new List {
            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 {
                    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. If your account supports EC2-Classic, Amazon EC2 launches the instances in EC2-Classic in the Availability Zone.

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


var response = client.RequestSpotFleet(new RequestSpotFleetRequest 
{
    SpotFleetRequestConfig = new SpotFleetRequestConfigData {
        IamFleetRole = "arn:aws:iam::123456789012:role/my-spot-fleet-role",
        LaunchSpecifications = new List {
            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 {
                    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 response = client.RequestSpotFleet(new RequestSpotFleetRequest 
{
    SpotFleetRequestConfig = new SpotFleetRequestConfigData {
        IamFleetRole = "arn:aws:iam::123456789012:role/my-spot-fleet-role",
        LaunchSpecifications = new List {
            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 {
                    new InstanceNetworkInterfaceSpecification {
                        AssociatePublicIpAddress = true,
                        DeviceIndex = 0,
                        Groups = new List {
                            "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 response = client.RequestSpotFleet(new RequestSpotFleetRequest 
{
    SpotFleetRequestConfig = new SpotFleetRequestConfigData {
        AllocationStrategy = "diversified",
        IamFleetRole = "arn:aws:iam::123456789012:role/my-spot-fleet-role",
        LaunchSpecifications = new List {
            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 Standard:
Supported in: 1.3

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

Portable Class Library:
Supported in: Windows Store Apps
Supported in: Windows Phone 8.1
Supported in: Xamarin Android
Supported in: Xamarin iOS (Unified)
Supported in: Xamarin.Forms