Class SpotFleetRequest


  • public class SpotFleetRequest
    extends com.pulumi.resources.CustomResource
    Provides an EC2 Spot Fleet Request resource. This allows a fleet of Spot instances to be requested on the Spot market. > **NOTE [AWS strongly discourages](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-best-practices.html#which-spot-request-method-to-use) the use of the legacy APIs called by this resource. We recommend using the EC2 Fleet or Auto Scaling group resources instead. ## Example Usage ### Using launch specifications
     
     package generated_program;
     
     import com.pulumi.Context;
     import com.pulumi.Pulumi;
     import com.pulumi.core.Output;
     import com.pulumi.aws.ec2.SpotFleetRequest;
     import com.pulumi.aws.ec2.SpotFleetRequestArgs;
     import com.pulumi.aws.ec2.inputs.SpotFleetRequestLaunchSpecificationArgs;
     import com.pulumi.aws.ec2.inputs.SpotFleetRequestLaunchSpecificationRootBlockDeviceArgs;
     import java.util.ArrayList;
     import java.util.Arrays;
     import java.util.Map;
     import java.io.File;
     import java.nio.file.Files;
     import java.nio.file.Paths;
     
     public class App {
         public static void main(String[] args) {
             Pulumi.run(App::stack);
         }
     
         public static void stack(Context ctx) {
             // Request a Spot fleet
             var cheapCompute = new SpotFleetRequest("cheapCompute", SpotFleetRequestArgs.builder()
                 .launchSpecifications(            
                     SpotFleetRequestLaunchSpecificationArgs.builder()
                         .instanceType("m4.10xlarge")
                         .ami("ami-1234")
                         .spotPrice("2.793")
                         .placementTenancy("dedicated")
                         .iamInstanceProfileArn(example.arn())
                         .build(),
                     SpotFleetRequestLaunchSpecificationArgs.builder()
                         .rootBlockDevices(SpotFleetRequestLaunchSpecificationRootBlockDeviceArgs.builder()
                             .volumeSize(300)
                             .volumeType("gp2")
                             .build())
                         .instanceType("m4.4xlarge")
                         .ami("ami-5678")
                         .keyName("my-key")
                         .spotPrice("1.117")
                         .iamInstanceProfileArn(example.arn())
                         .availabilityZone("us-west-1a")
                         .subnetId("subnet-1234")
                         .weightedCapacity("35")
                         .tags(Map.of("Name", "spot-fleet-example"))
                         .build())
                 .iamFleetRole("arn:aws:iam::12345678:role/spot-fleet")
                 .spotPrice("0.03")
                 .allocationStrategy("diversified")
                 .targetCapacity(6)
                 .validUntil("2019-11-04T20:44:20Z")
                 .build());
     
         }
     }
     
     
    ### Using launch templates
     
     package generated_program;
     
     import com.pulumi.Context;
     import com.pulumi.Pulumi;
     import com.pulumi.core.Output;
     import com.pulumi.aws.ec2.LaunchTemplate;
     import com.pulumi.aws.ec2.LaunchTemplateArgs;
     import com.pulumi.aws.ec2.SpotFleetRequest;
     import com.pulumi.aws.ec2.SpotFleetRequestArgs;
     import com.pulumi.aws.ec2.inputs.SpotFleetRequestLaunchTemplateConfigArgs;
     import com.pulumi.aws.ec2.inputs.SpotFleetRequestLaunchTemplateConfigLaunchTemplateSpecificationArgs;
     import com.pulumi.resources.CustomResourceOptions;
     import java.util.ArrayList;
     import java.util.Arrays;
     import java.util.Map;
     import java.io.File;
     import java.nio.file.Files;
     import java.nio.file.Paths;
     
     public class App {
         public static void main(String[] args) {
             Pulumi.run(App::stack);
         }
     
         public static void stack(Context ctx) {
             var foo = new LaunchTemplate("foo", LaunchTemplateArgs.builder()
                 .name("launch-template")
                 .imageId("ami-516b9131")
                 .instanceType("m1.small")
                 .keyName("some-key")
                 .build());
     
             var fooSpotFleetRequest = new SpotFleetRequest("fooSpotFleetRequest", SpotFleetRequestArgs.builder()
                 .launchTemplateConfigs(SpotFleetRequestLaunchTemplateConfigArgs.builder()
                     .launchTemplateSpecification(SpotFleetRequestLaunchTemplateConfigLaunchTemplateSpecificationArgs.builder()
                         .id(foo.id())
                         .version(foo.latestVersion())
                         .build())
                     .build())
                 .iamFleetRole("arn:aws:iam::12345678:role/spot-fleet")
                 .spotPrice("0.005")
                 .targetCapacity(2)
                 .validUntil("2019-11-04T20:44:20Z")
                 .build(), CustomResourceOptions.builder()
                     .dependsOn(test_attach)
                     .build());
     
         }
     }
     
     
    > **NOTE:** This provider does not support the functionality where multiple `subnetId` or `availabilityZone` parameters can be specified in the same launch configuration block. If you want to specify multiple values, then separate launch configuration blocks should be used or launch template overrides should be configured, one per subnet: ### Using multiple launch specifications
     
     package generated_program;
     
     import com.pulumi.Context;
     import com.pulumi.Pulumi;
     import com.pulumi.core.Output;
     import com.pulumi.aws.ec2.SpotFleetRequest;
     import com.pulumi.aws.ec2.SpotFleetRequestArgs;
     import com.pulumi.aws.ec2.inputs.SpotFleetRequestLaunchSpecificationArgs;
     import java.util.ArrayList;
     import java.util.Arrays;
     import java.util.Map;
     import java.io.File;
     import java.nio.file.Files;
     import java.nio.file.Paths;
     
     public class App {
         public static void main(String[] args) {
             Pulumi.run(App::stack);
         }
     
         public static void stack(Context ctx) {
             var foo = new SpotFleetRequest("foo", SpotFleetRequestArgs.builder()
                 .launchSpecifications(            
                     SpotFleetRequestLaunchSpecificationArgs.builder()
                         .instanceType("m1.small")
                         .ami("ami-d06a90b0")
                         .keyName("my-key")
                         .availabilityZone("us-west-2a")
                         .build(),
                     SpotFleetRequestLaunchSpecificationArgs.builder()
                         .instanceType("m5.large")
                         .ami("ami-d06a90b0")
                         .keyName("my-key")
                         .availabilityZone("us-west-2a")
                         .build())
                 .iamFleetRole("arn:aws:iam::12345678:role/spot-fleet")
                 .spotPrice("0.005")
                 .targetCapacity(2)
                 .validUntil("2019-11-04T20:44:20Z")
                 .build());
     
         }
     }
     
     
    > In this example, we use a `dynamic` block to define zero or more `launchSpecification` blocks, producing one for each element in the list of subnet IDs. ### Using multiple launch configurations
     
     package generated_program;
     
     import com.pulumi.Context;
     import com.pulumi.Pulumi;
     import com.pulumi.core.Output;
     import com.pulumi.aws.ec2.Ec2Functions;
     import com.pulumi.aws.ec2.inputs.GetSubnetsArgs;
     import com.pulumi.aws.ec2.inputs.GetSubnetsFilterArgs;
     import com.pulumi.aws.ec2.LaunchTemplate;
     import com.pulumi.aws.ec2.LaunchTemplateArgs;
     import com.pulumi.aws.ec2.SpotFleetRequest;
     import com.pulumi.aws.ec2.SpotFleetRequestArgs;
     import com.pulumi.aws.ec2.inputs.SpotFleetRequestLaunchTemplateConfigArgs;
     import com.pulumi.aws.ec2.inputs.SpotFleetRequestLaunchTemplateConfigLaunchTemplateSpecificationArgs;
     import com.pulumi.aws.ec2.inputs.SpotFleetRequestLaunchTemplateConfigOverrideArgs;
     import com.pulumi.resources.CustomResourceOptions;
     import java.util.ArrayList;
     import java.util.Arrays;
     import java.util.Map;
     import java.io.File;
     import java.nio.file.Files;
     import java.nio.file.Paths;
     
     public class App {
         public static void main(String[] args) {
             Pulumi.run(App::stack);
         }
     
         public static void stack(Context ctx) {
             final var example = Ec2Functions.getSubnets(GetSubnetsArgs.builder()
                 .filters(GetSubnetsFilterArgs.builder()
                     .name("vpc-id")
                     .values(vpcId)
                     .build())
                 .build());
     
             var foo = new LaunchTemplate("foo", LaunchTemplateArgs.builder()
                 .name("launch-template")
                 .imageId("ami-516b9131")
                 .instanceType("m1.small")
                 .keyName("some-key")
                 .build());
     
             var fooSpotFleetRequest = new SpotFleetRequest("fooSpotFleetRequest", SpotFleetRequestArgs.builder()
                 .launchTemplateConfigs(SpotFleetRequestLaunchTemplateConfigArgs.builder()
                     .launchTemplateSpecification(SpotFleetRequestLaunchTemplateConfigLaunchTemplateSpecificationArgs.builder()
                         .id(foo.id())
                         .version(foo.latestVersion())
                         .build())
                     .overrides(                
                         SpotFleetRequestLaunchTemplateConfigOverrideArgs.builder()
                             .subnetId(example.ids()[0])
                             .build(),
                         SpotFleetRequestLaunchTemplateConfigOverrideArgs.builder()
                             .subnetId(example.ids()[1])
                             .build(),
                         SpotFleetRequestLaunchTemplateConfigOverrideArgs.builder()
                             .subnetId(example.ids()[2])
                             .build())
                     .build())
                 .iamFleetRole("arn:aws:iam::12345678:role/spot-fleet")
                 .spotPrice("0.005")
                 .targetCapacity(2)
                 .validUntil("2019-11-04T20:44:20Z")
                 .build(), CustomResourceOptions.builder()
                     .dependsOn(test_attach)
                     .build());
     
         }
     }
     
     
    ## Import Using `pulumi import`, import Spot Fleet Requests using `id`. For example: ```sh $ pulumi import aws:ec2/spotFleetRequest:SpotFleetRequest fleet sfr-005e9ec8-5546-4c31-b317-31a62325411e ```
    • Nested Class Summary

      • Nested classes/interfaces inherited from class com.pulumi.resources.CustomResource

        com.pulumi.resources.CustomResource.CustomResourceInternal
      • Nested classes/interfaces inherited from class com.pulumi.resources.Resource

        com.pulumi.resources.Resource.LazyField<T extends java.lang.Object>, com.pulumi.resources.Resource.LazyFields, com.pulumi.resources.Resource.ResourceInternal
    • Field Summary

      • Fields inherited from class com.pulumi.resources.Resource

        childResources, remote
    • Constructor Detail

      • SpotFleetRequest

        public SpotFleetRequest​(java.lang.String name)
        Parameters:
        name - The _unique_ name of the resulting resource.
      • SpotFleetRequest

        public SpotFleetRequest​(java.lang.String name,
                                SpotFleetRequestArgs args)
        Parameters:
        name - The _unique_ name of the resulting resource.
        args - The arguments to use to populate this resource's properties.
      • SpotFleetRequest

        public SpotFleetRequest​(java.lang.String name,
                                SpotFleetRequestArgs args,
                                @Nullable
                                com.pulumi.resources.CustomResourceOptions options)
        Parameters:
        name - The _unique_ name of the resulting resource.
        args - The arguments to use to populate this resource's properties.
        options - A bag of options that control this resource's behavior.
    • Method Detail

      • allocationStrategy

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> allocationStrategy()
        Returns:
        Indicates how to allocate the target capacity across the Spot pools specified by the Spot fleet request. Valid values: `lowestPrice`, `diversified`, `capacityOptimized`, `capacityOptimizedPrioritized`, and `priceCapacityOptimized`. The default is `lowestPrice`.
      • clientToken

        public com.pulumi.core.Output<java.lang.String> clientToken()
      • context

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> context()
        Returns:
        Reserved.
      • excessCapacityTerminationPolicy

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> excessCapacityTerminationPolicy()
        Returns:
        Indicates whether running Spot instances should be terminated if the target capacity of the Spot fleet request is decreased below the current size of the Spot fleet.
      • fleetType

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> fleetType()
        Returns:
        The type of fleet request. Indicates whether the Spot Fleet only requests the target capacity or also attempts to maintain it. Default is `maintain`.
      • iamFleetRole

        public com.pulumi.core.Output<java.lang.String> iamFleetRole()
        Returns:
        Grants the Spot fleet permission to terminate Spot instances on your behalf when you cancel its Spot fleet request using CancelSpotFleetRequests or when the Spot fleet request expires, if you set terminateInstancesWithExpiration.
      • instanceInterruptionBehaviour

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> instanceInterruptionBehaviour()
        Returns:
        Indicates whether a Spot instance stops or terminates when it is interrupted. Default is `terminate`.
      • instancePoolsToUseCount

        public com.pulumi.core.Output<java.util.Optional<java.lang.Integer>> instancePoolsToUseCount()
        Returns:
        The number of Spot pools across which to allocate your target Spot capacity. Valid only when `allocationStrategy` is set to `lowestPrice`. Spot Fleet selects the cheapest Spot pools and evenly allocates your target Spot capacity across the number of Spot pools that you specify.
      • launchSpecifications

        public com.pulumi.core.Output<java.util.Optional<java.util.List<SpotFleetRequestLaunchSpecification>>> launchSpecifications()
        Returns:
        Used to define the launch configuration of the spot-fleet request. Can be specified multiple times to define different bids across different markets and instance types. Conflicts with `launchTemplateConfig`. At least one of `launchSpecification` or `launchTemplateConfig` is required. **Note**: This takes in similar but not identical inputs as `aws.ec2.Instance`. There are limitations on what you can specify. See the list of officially supported inputs in the [reference documentation](http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_SpotFleetLaunchSpecification.html). Any normal `aws.ec2.Instance` parameter that corresponds to those inputs may be used and it have a additional parameter `iamInstanceProfileArn` takes `aws.iam.InstanceProfile` attribute `arn` as input.
      • launchTemplateConfigs

        public com.pulumi.core.Output<java.util.Optional<java.util.List<SpotFleetRequestLaunchTemplateConfig>>> launchTemplateConfigs()
        Returns:
        Launch template configuration block. See Launch Template Configs below for more details. Conflicts with `launchSpecification`. At least one of `launchSpecification` or `launchTemplateConfig` is required.
      • loadBalancers

        public com.pulumi.core.Output<java.util.List<java.lang.String>> loadBalancers()
        Returns:
        A list of elastic load balancer names to add to the Spot fleet.
      • onDemandAllocationStrategy

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> onDemandAllocationStrategy()
        Returns:
        The order of the launch template overrides to use in fulfilling On-Demand capacity. the possible values are: `lowestPrice` and `prioritized`. the default is `lowestPrice`.
      • onDemandMaxTotalPrice

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> onDemandMaxTotalPrice()
        Returns:
        The maximum amount per hour for On-Demand Instances that you're willing to pay. When the maximum amount you're willing to pay is reached, the fleet stops launching instances even if it hasn’t met the target capacity.
      • onDemandTargetCapacity

        public com.pulumi.core.Output<java.util.Optional<java.lang.Integer>> onDemandTargetCapacity()
        Returns:
        The number of On-Demand units to request. If the request type is `maintain`, you can specify a target capacity of 0 and add capacity later.
      • region

        public com.pulumi.core.Output<java.lang.String> region()
        Returns:
        Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the provider configuration.
      • replaceUnhealthyInstances

        public com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> replaceUnhealthyInstances()
        Returns:
        Indicates whether Spot fleet should replace unhealthy instances. Default `false`.
      • spotMaintenanceStrategies

        public com.pulumi.core.Output<java.util.Optional<SpotFleetRequestSpotMaintenanceStrategies>> spotMaintenanceStrategies()
        Returns:
        Nested argument containing maintenance strategies for managing your Spot Instances that are at an elevated risk of being interrupted. Defined below.
      • spotPrice

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> spotPrice()
        Returns:
        The maximum bid price per unit hour.
      • spotRequestState

        public com.pulumi.core.Output<java.lang.String> spotRequestState()
        Returns:
        The state of the Spot fleet request.
      • tags

        public com.pulumi.core.Output<java.util.Optional<java.util.Map<java.lang.String,​java.lang.String>>> tags()
        Returns:
        A map of tags to assign to the resource. .If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
      • tagsAll

        public com.pulumi.core.Output<java.util.Map<java.lang.String,​java.lang.String>> tagsAll()
        Returns:
        A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
      • targetCapacity

        public com.pulumi.core.Output<java.lang.Integer> targetCapacity()
        Returns:
        The number of units to request. You can choose to set the target capacity in terms of instances or a performance characteristic that is important to your application workload, such as vCPUs, memory, or I/O.
      • targetCapacityUnitType

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> targetCapacityUnitType()
        Returns:
        The unit for the target capacity. This can only be done with `instanceRequirements` defined
      • targetGroupArns

        public com.pulumi.core.Output<java.util.List<java.lang.String>> targetGroupArns()
        Returns:
        A list of `aws.alb.TargetGroup` ARNs, for use with Application Load Balancing.
      • terminateInstancesOnDelete

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> terminateInstancesOnDelete()
        Returns:
        Indicates whether running Spot instances should be terminated when the resource is deleted (and the Spot fleet request cancelled). If no value is specified, the value of the `terminateInstancesWithExpiration` argument is used.
      • terminateInstancesWithExpiration

        public com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> terminateInstancesWithExpiration()
        Returns:
        Indicates whether running Spot instances should be terminated when the Spot fleet request expires.
      • validFrom

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> validFrom()
        Returns:
        The start date and time of the request, in UTC [RFC3339](https://tools.ietf.org/html/rfc3339#section-5.8) format(for example, YYYY-MM-DDTHH:MM:SSZ). The default is to start fulfilling the request immediately.
      • validUntil

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> validUntil()
        Returns:
        The end date and time of the request, in UTC [RFC3339](https://tools.ietf.org/html/rfc3339#section-5.8) format(for example, YYYY-MM-DDTHH:MM:SSZ). At this point, no new Spot instance requests are placed or enabled to fulfill the request.
      • waitForFulfillment

        public com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> waitForFulfillment()
        Returns:
        If set, this provider will wait for the Spot Request to be fulfilled, and will throw an error if the timeout of 10m is reached.
      • get

        public static SpotFleetRequest get​(java.lang.String name,
                                           com.pulumi.core.Output<java.lang.String> id,
                                           @Nullable
                                           SpotFleetRequestState state,
                                           @Nullable
                                           com.pulumi.resources.CustomResourceOptions options)
        Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.
        Parameters:
        name - The _unique_ name of the resulting resource.
        id - The _unique_ provider ID of the resource to lookup.
        state -
        options - Optional settings to control the behavior of the CustomResource.