SpotFleetRequestArgs

data class SpotFleetRequestArgs(val allocationStrategy: Output<String>? = null, val context: Output<String>? = null, val excessCapacityTerminationPolicy: Output<String>? = null, val fleetType: Output<String>? = null, val iamFleetRole: Output<String>? = null, val instanceInterruptionBehaviour: Output<String>? = null, val instancePoolsToUseCount: Output<Int>? = null, val launchSpecifications: Output<List<SpotFleetRequestLaunchSpecificationArgs>>? = null, val launchTemplateConfigs: Output<List<SpotFleetRequestLaunchTemplateConfigArgs>>? = null, val loadBalancers: Output<List<String>>? = null, val onDemandAllocationStrategy: Output<String>? = null, val onDemandMaxTotalPrice: Output<String>? = null, val onDemandTargetCapacity: Output<Int>? = null, val replaceUnhealthyInstances: Output<Boolean>? = null, val spotMaintenanceStrategies: Output<SpotFleetRequestSpotMaintenanceStrategiesArgs>? = null, val spotPrice: Output<String>? = null, val tags: Output<Map<String, String>>? = null, val targetCapacity: Output<Int>? = null, val targetCapacityUnitType: Output<String>? = null, val targetGroupArns: Output<List<String>>? = null, val terminateInstancesOnDelete: Output<String>? = null, val terminateInstancesWithExpiration: Output<Boolean>? = null, val validFrom: Output<String>? = null, val validUntil: Output<String>? = null, val waitForFulfillment: Output<Boolean>? = null) : ConvertibleToJava<SpotFleetRequestArgs>

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

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Request a Spot fleet
const cheapCompute = new aws.ec2.SpotFleetRequest("cheap_compute", {
iamFleetRole: "arn:aws:iam::12345678:role/spot-fleet",
spotPrice: "0.03",
allocationStrategy: "diversified",
targetCapacity: 6,
validUntil: "2019-11-04T20:44:20Z",
launchSpecifications: [
{
instanceType: "m4.10xlarge",
ami: "ami-1234",
spotPrice: "2.793",
placementTenancy: "dedicated",
iamInstanceProfileArn: example.arn,
},
{
instanceType: "m4.4xlarge",
ami: "ami-5678",
keyName: "my-key",
spotPrice: "1.117",
iamInstanceProfileArn: example.arn,
availabilityZone: "us-west-1a",
subnetId: "subnet-1234",
weightedCapacity: "35",
rootBlockDevices: [{
volumeSize: 300,
volumeType: "gp2",
}],
tags: {
Name: "spot-fleet-example",
},
},
],
});
import pulumi
import pulumi_aws as aws
# Request a Spot fleet
cheap_compute = aws.ec2.SpotFleetRequest("cheap_compute",
iam_fleet_role="arn:aws:iam::12345678:role/spot-fleet",
spot_price="0.03",
allocation_strategy="diversified",
target_capacity=6,
valid_until="2019-11-04T20:44:20Z",
launch_specifications=[
{
"instance_type": "m4.10xlarge",
"ami": "ami-1234",
"spot_price": "2.793",
"placement_tenancy": "dedicated",
"iam_instance_profile_arn": example["arn"],
},
{
"instance_type": "m4.4xlarge",
"ami": "ami-5678",
"key_name": "my-key",
"spot_price": "1.117",
"iam_instance_profile_arn": example["arn"],
"availability_zone": "us-west-1a",
"subnet_id": "subnet-1234",
"weighted_capacity": "35",
"root_block_devices": [{
"volume_size": 300,
"volume_type": "gp2",
}],
"tags": {
"Name": "spot-fleet-example",
},
},
])
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
// Request a Spot fleet
var cheapCompute = new Aws.Ec2.SpotFleetRequest("cheap_compute", new()
{
IamFleetRole = "arn:aws:iam::12345678:role/spot-fleet",
SpotPrice = "0.03",
AllocationStrategy = "diversified",
TargetCapacity = 6,
ValidUntil = "2019-11-04T20:44:20Z",
LaunchSpecifications = new[]
{
new Aws.Ec2.Inputs.SpotFleetRequestLaunchSpecificationArgs
{
InstanceType = "m4.10xlarge",
Ami = "ami-1234",
SpotPrice = "2.793",
PlacementTenancy = "dedicated",
IamInstanceProfileArn = example.Arn,
},
new Aws.Ec2.Inputs.SpotFleetRequestLaunchSpecificationArgs
{
InstanceType = "m4.4xlarge",
Ami = "ami-5678",
KeyName = "my-key",
SpotPrice = "1.117",
IamInstanceProfileArn = example.Arn,
AvailabilityZone = "us-west-1a",
SubnetId = "subnet-1234",
WeightedCapacity = "35",
RootBlockDevices = new[]
{
new Aws.Ec2.Inputs.SpotFleetRequestLaunchSpecificationRootBlockDeviceArgs
{
VolumeSize = 300,
VolumeType = "gp2",
},
},
Tags =
{
{ "Name", "spot-fleet-example" },
},
},
},
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
// Request a Spot fleet
_, err := ec2.NewSpotFleetRequest(ctx, "cheap_compute", &ec2.SpotFleetRequestArgs{
IamFleetRole: pulumi.String("arn:aws:iam::12345678:role/spot-fleet"),
SpotPrice: pulumi.String("0.03"),
AllocationStrategy: pulumi.String("diversified"),
TargetCapacity: pulumi.Int(6),
ValidUntil: pulumi.String("2019-11-04T20:44:20Z"),
LaunchSpecifications: ec2.SpotFleetRequestLaunchSpecificationArray{
&ec2.SpotFleetRequestLaunchSpecificationArgs{
InstanceType: pulumi.String("m4.10xlarge"),
Ami: pulumi.String("ami-1234"),
SpotPrice: pulumi.String("2.793"),
PlacementTenancy: pulumi.String("dedicated"),
IamInstanceProfileArn: pulumi.Any(example.Arn),
},
&ec2.SpotFleetRequestLaunchSpecificationArgs{
InstanceType: pulumi.String("m4.4xlarge"),
Ami: pulumi.String("ami-5678"),
KeyName: pulumi.String("my-key"),
SpotPrice: pulumi.String("1.117"),
IamInstanceProfileArn: pulumi.Any(example.Arn),
AvailabilityZone: pulumi.String("us-west-1a"),
SubnetId: pulumi.String("subnet-1234"),
WeightedCapacity: pulumi.String("35"),
RootBlockDevices: ec2.SpotFleetRequestLaunchSpecificationRootBlockDeviceArray{
&ec2.SpotFleetRequestLaunchSpecificationRootBlockDeviceArgs{
VolumeSize: pulumi.Int(300),
VolumeType: pulumi.String("gp2"),
},
},
Tags: pulumi.StringMap{
"Name": pulumi.String("spot-fleet-example"),
},
},
},
})
if err != nil {
return err
}
return nil
})
}
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.List;
import java.util.ArrayList;
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()
.iamFleetRole("arn:aws:iam::12345678:role/spot-fleet")
.spotPrice("0.03")
.allocationStrategy("diversified")
.targetCapacity(6)
.validUntil("2019-11-04T20:44:20Z")
.launchSpecifications(
SpotFleetRequestLaunchSpecificationArgs.builder()
.instanceType("m4.10xlarge")
.ami("ami-1234")
.spotPrice("2.793")
.placementTenancy("dedicated")
.iamInstanceProfileArn(example.arn())
.build(),
SpotFleetRequestLaunchSpecificationArgs.builder()
.instanceType("m4.4xlarge")
.ami("ami-5678")
.keyName("my-key")
.spotPrice("1.117")
.iamInstanceProfileArn(example.arn())
.availabilityZone("us-west-1a")
.subnetId("subnet-1234")
.weightedCapacity(35)
.rootBlockDevices(SpotFleetRequestLaunchSpecificationRootBlockDeviceArgs.builder()
.volumeSize("300")
.volumeType("gp2")
.build())
.tags(Map.of("Name", "spot-fleet-example"))
.build())
.build());
}
}
resources:
# Request a Spot fleet
cheapCompute:
type: aws:ec2:SpotFleetRequest
name: cheap_compute
properties:
iamFleetRole: arn:aws:iam::12345678:role/spot-fleet
spotPrice: '0.03'
allocationStrategy: diversified
targetCapacity: 6
validUntil: 2019-11-04T20:44:20Z
launchSpecifications:
- instanceType: m4.10xlarge
ami: ami-1234
spotPrice: '2.793'
placementTenancy: dedicated
iamInstanceProfileArn: ${example.arn}
- instanceType: m4.4xlarge
ami: ami-5678
keyName: my-key
spotPrice: '1.117'
iamInstanceProfileArn: ${example.arn}
availabilityZone: us-west-1a
subnetId: subnet-1234
weightedCapacity: 35
rootBlockDevices:
- volumeSize: '300'
volumeType: gp2
tags:
Name: spot-fleet-example

Using launch templates

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const foo = new aws.ec2.LaunchTemplate("foo", {
name: "launch-template",
imageId: "ami-516b9131",
instanceType: "m1.small",
keyName: "some-key",
});
const fooSpotFleetRequest = new aws.ec2.SpotFleetRequest("foo", {
iamFleetRole: "arn:aws:iam::12345678:role/spot-fleet",
spotPrice: "0.005",
targetCapacity: 2,
validUntil: "2019-11-04T20:44:20Z",
launchTemplateConfigs: [{
launchTemplateSpecification: {
id: foo.id,
version: foo.latestVersion,
},
}],
}, {
dependsOn: [test_attach],
});
import pulumi
import pulumi_aws as aws
foo = aws.ec2.LaunchTemplate("foo",
name="launch-template",
image_id="ami-516b9131",
instance_type="m1.small",
key_name="some-key")
foo_spot_fleet_request = aws.ec2.SpotFleetRequest("foo",
iam_fleet_role="arn:aws:iam::12345678:role/spot-fleet",
spot_price="0.005",
target_capacity=2,
valid_until="2019-11-04T20:44:20Z",
launch_template_configs=[{
"launch_template_specification": {
"id": foo.id,
"version": foo.latest_version,
},
}],
opts = pulumi.ResourceOptions(depends_on=[test_attach]))
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var foo = new Aws.Ec2.LaunchTemplate("foo", new()
{
Name = "launch-template",
ImageId = "ami-516b9131",
InstanceType = "m1.small",
KeyName = "some-key",
});
var fooSpotFleetRequest = new Aws.Ec2.SpotFleetRequest("foo", new()
{
IamFleetRole = "arn:aws:iam::12345678:role/spot-fleet",
SpotPrice = "0.005",
TargetCapacity = 2,
ValidUntil = "2019-11-04T20:44:20Z",
LaunchTemplateConfigs = new[]
{
new Aws.Ec2.Inputs.SpotFleetRequestLaunchTemplateConfigArgs
{
LaunchTemplateSpecification = new Aws.Ec2.Inputs.SpotFleetRequestLaunchTemplateConfigLaunchTemplateSpecificationArgs
{
Id = foo.Id,
Version = foo.LatestVersion,
},
},
},
}, new CustomResourceOptions
{
DependsOn =
{
test_attach,
},
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
foo, err := ec2.NewLaunchTemplate(ctx, "foo", &ec2.LaunchTemplateArgs{
Name: pulumi.String("launch-template"),
ImageId: pulumi.String("ami-516b9131"),
InstanceType: pulumi.String("m1.small"),
KeyName: pulumi.String("some-key"),
})
if err != nil {
return err
}
_, err = ec2.NewSpotFleetRequest(ctx, "foo", &ec2.SpotFleetRequestArgs{
IamFleetRole: pulumi.String("arn:aws:iam::12345678:role/spot-fleet"),
SpotPrice: pulumi.String("0.005"),
TargetCapacity: pulumi.Int(2),
ValidUntil: pulumi.String("2019-11-04T20:44:20Z"),
LaunchTemplateConfigs: ec2.SpotFleetRequestLaunchTemplateConfigArray{
&ec2.SpotFleetRequestLaunchTemplateConfigArgs{
LaunchTemplateSpecification: &ec2.SpotFleetRequestLaunchTemplateConfigLaunchTemplateSpecificationArgs{
Id: foo.ID(),
Version: foo.LatestVersion,
},
},
},
}, pulumi.DependsOn([]pulumi.Resource{
test_attach,
}))
if err != nil {
return err
}
return nil
})
}
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.List;
import java.util.ArrayList;
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()
.iamFleetRole("arn:aws:iam::12345678:role/spot-fleet")
.spotPrice("0.005")
.targetCapacity(2)
.validUntil("2019-11-04T20:44:20Z")
.launchTemplateConfigs(SpotFleetRequestLaunchTemplateConfigArgs.builder()
.launchTemplateSpecification(SpotFleetRequestLaunchTemplateConfigLaunchTemplateSpecificationArgs.builder()
.id(foo.id())
.version(foo.latestVersion())
.build())
.build())
.build(), CustomResourceOptions.builder()
.dependsOn(test_attach)
.build());
}
}
resources:
foo:
type: aws:ec2:LaunchTemplate
properties:
name: launch-template
imageId: ami-516b9131
instanceType: m1.small
keyName: some-key
fooSpotFleetRequest:
type: aws:ec2:SpotFleetRequest
name: foo
properties:
iamFleetRole: arn:aws:iam::12345678:role/spot-fleet
spotPrice: '0.005'
targetCapacity: 2
validUntil: 2019-11-04T20:44:20Z
launchTemplateConfigs:
- launchTemplateSpecification:
id: ${foo.id}
version: ${foo.latestVersion}
options:
dependsOn:
- ${["test-attach"]}

NOTE: This provider does not support the functionality where multiple subnet_id or availability_zone 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

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const foo = new aws.ec2.SpotFleetRequest("foo", {
iamFleetRole: "arn:aws:iam::12345678:role/spot-fleet",
spotPrice: "0.005",
targetCapacity: 2,
validUntil: "2019-11-04T20:44:20Z",
launchSpecifications: [
{
instanceType: "m1.small",
ami: "ami-d06a90b0",
keyName: "my-key",
availabilityZone: "us-west-2a",
},
{
instanceType: "m5.large",
ami: "ami-d06a90b0",
keyName: "my-key",
availabilityZone: "us-west-2a",
},
],
});
import pulumi
import pulumi_aws as aws
foo = aws.ec2.SpotFleetRequest("foo",
iam_fleet_role="arn:aws:iam::12345678:role/spot-fleet",
spot_price="0.005",
target_capacity=2,
valid_until="2019-11-04T20:44:20Z",
launch_specifications=[
{
"instance_type": "m1.small",
"ami": "ami-d06a90b0",
"key_name": "my-key",
"availability_zone": "us-west-2a",
},
{
"instance_type": "m5.large",
"ami": "ami-d06a90b0",
"key_name": "my-key",
"availability_zone": "us-west-2a",
},
])
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var foo = new Aws.Ec2.SpotFleetRequest("foo", new()
{
IamFleetRole = "arn:aws:iam::12345678:role/spot-fleet",
SpotPrice = "0.005",
TargetCapacity = 2,
ValidUntil = "2019-11-04T20:44:20Z",
LaunchSpecifications = new[]
{
new Aws.Ec2.Inputs.SpotFleetRequestLaunchSpecificationArgs
{
InstanceType = "m1.small",
Ami = "ami-d06a90b0",
KeyName = "my-key",
AvailabilityZone = "us-west-2a",
},
new Aws.Ec2.Inputs.SpotFleetRequestLaunchSpecificationArgs
{
InstanceType = "m5.large",
Ami = "ami-d06a90b0",
KeyName = "my-key",
AvailabilityZone = "us-west-2a",
},
},
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := ec2.NewSpotFleetRequest(ctx, "foo", &ec2.SpotFleetRequestArgs{
IamFleetRole: pulumi.String("arn:aws:iam::12345678:role/spot-fleet"),
SpotPrice: pulumi.String("0.005"),
TargetCapacity: pulumi.Int(2),
ValidUntil: pulumi.String("2019-11-04T20:44:20Z"),
LaunchSpecifications: ec2.SpotFleetRequestLaunchSpecificationArray{
&ec2.SpotFleetRequestLaunchSpecificationArgs{
InstanceType: pulumi.String("m1.small"),
Ami: pulumi.String("ami-d06a90b0"),
KeyName: pulumi.String("my-key"),
AvailabilityZone: pulumi.String("us-west-2a"),
},
&ec2.SpotFleetRequestLaunchSpecificationArgs{
InstanceType: pulumi.String("m5.large"),
Ami: pulumi.String("ami-d06a90b0"),
KeyName: pulumi.String("my-key"),
AvailabilityZone: pulumi.String("us-west-2a"),
},
},
})
if err != nil {
return err
}
return nil
})
}
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.List;
import java.util.ArrayList;
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()
.iamFleetRole("arn:aws:iam::12345678:role/spot-fleet")
.spotPrice("0.005")
.targetCapacity(2)
.validUntil("2019-11-04T20:44:20Z")
.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())
.build());
}
}
resources:
foo:
type: aws:ec2:SpotFleetRequest
properties:
iamFleetRole: arn:aws:iam::12345678:role/spot-fleet
spotPrice: '0.005'
targetCapacity: 2
validUntil: 2019-11-04T20:44:20Z
launchSpecifications:
- instanceType: m1.small
ami: ami-d06a90b0
keyName: my-key
availabilityZone: us-west-2a
- instanceType: m5.large
ami: ami-d06a90b0
keyName: my-key
availabilityZone: us-west-2a

In this example, we use a dynamic block to define zero or more launch_specification blocks, producing one for each element in the list of subnet ids.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const config = new pulumi.Config();
const subnets = config.requireObject("subnets");
const example = new aws.ec2.SpotFleetRequest("example", {
launchSpecifications: .map(s => ({
subnetId: s[1],
})).map((v, k) => ({key: k, value: v})).map(entry => ({
ami: "ami-1234",
instanceType: "m4.4xlarge",
subnetId: entry.value.subnetId,
vpcSecurityGroupIds: "sg-123456",
rootBlockDevices: [{
volumeSize: 8,
volumeType: "gp2",
deleteOnTermination: true,
}],
tags: {
Name: "Spot Node",
tag_builder: "builder",
},
})),
iamFleetRole: "arn:aws:iam::12345678:role/spot-fleet",
targetCapacity: 3,
validUntil: "2019-11-04T20:44:20Z",
allocationStrategy: "lowestPrice",
fleetType: "request",
waitForFulfillment: true,
terminateInstancesWithExpiration: true,
});
import pulumi
import pulumi_aws as aws
config = pulumi.Config()
subnets = config.require_object("subnets")
example = aws.ec2.SpotFleetRequest("example",
launch_specifications=[{
"ami": "ami-1234",
"instance_type": "m4.4xlarge",
"subnet_id": entry["value"]["subnetId"],
"vpc_security_group_ids": "sg-123456",
"root_block_devices": [{
"volume_size": 8,
"volume_type": "gp2",
"delete_on_termination": True,
}],
"tags": {
"Name": "Spot Node",
"tag_builder": "builder",
},
} for entry in [{"key": k, "value": v} for k, v in [{
"subnetId": s[1],
} for s in subnets]]],
iam_fleet_role="arn:aws:iam::12345678:role/spot-fleet",
target_capacity=3,
valid_until="2019-11-04T20:44:20Z",
allocation_strategy="lowestPrice",
fleet_type="request",
wait_for_fulfillment=True,
terminate_instances_with_expiration=True)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var config = new Config();
var subnets = config.RequireObject<dynamic>("subnets");
var example = new Aws.Ec2.SpotFleetRequest("example", new()
{
LaunchSpecifications = .Select(s =>
{
return
{
{ "subnetId", s[1] },
};
}).ToList().Select((v, k) => new { Key = k, Value = v }).Select(entry =>
{
return new Aws.Ec2.Inputs.SpotFleetRequestLaunchSpecificationArgs
{
Ami = "ami-1234",
InstanceType = "m4.4xlarge",
SubnetId = entry.Value.SubnetId,
VpcSecurityGroupIds = "sg-123456",
RootBlockDevices = new[]
{
new Aws.Ec2.Inputs.SpotFleetRequestLaunchSpecificationRootBlockDeviceArgs
{
VolumeSize = 8,
VolumeType = "gp2",
DeleteOnTermination = true,
},
},
Tags =
{
{ "Name", "Spot Node" },
{ "tag_builder", "builder" },
},
};
}).ToList(),
IamFleetRole = "arn:aws:iam::12345678:role/spot-fleet",
TargetCapacity = 3,
ValidUntil = "2019-11-04T20:44:20Z",
AllocationStrategy = "lowestPrice",
FleetType = "request",
WaitForFulfillment = true,
TerminateInstancesWithExpiration = true,
});
});

Using multiple launch configurations

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const example = aws.ec2.getSubnets({
filters: [{
name: "vpc-id",
values: [vpcId],
}],
});
const foo = new aws.ec2.LaunchTemplate("foo", {
name: "launch-template",
imageId: "ami-516b9131",
instanceType: "m1.small",
keyName: "some-key",
});
const fooSpotFleetRequest = new aws.ec2.SpotFleetRequest("foo", {
iamFleetRole: "arn:aws:iam::12345678:role/spot-fleet",
spotPrice: "0.005",
targetCapacity: 2,
validUntil: "2019-11-04T20:44:20Z",
launchTemplateConfigs: [{
launchTemplateSpecification: {
id: foo.id,
version: foo.latestVersion,
},
overrides: [
{
subnetId: example.then(example => example.ids?.[0]),
},
{
subnetId: example.then(example => example.ids?.[1]),
},
{
subnetId: example.then(example => example.ids?.[2]),
},
],
}],
}, {
dependsOn: [test_attach],
});
import pulumi
import pulumi_aws as aws
example = aws.ec2.get_subnets(filters=[{
"name": "vpc-id",
"values": [vpc_id],
}])
foo = aws.ec2.LaunchTemplate("foo",
name="launch-template",
image_id="ami-516b9131",
instance_type="m1.small",
key_name="some-key")
foo_spot_fleet_request = aws.ec2.SpotFleetRequest("foo",
iam_fleet_role="arn:aws:iam::12345678:role/spot-fleet",
spot_price="0.005",
target_capacity=2,
valid_until="2019-11-04T20:44:20Z",
launch_template_configs=[{
"launch_template_specification": {
"id": foo.id,
"version": foo.latest_version,
},
"overrides": [
{
"subnet_id": example.ids[0],
},
{
"subnet_id": example.ids[1],
},
{
"subnet_id": example.ids[2],
},
],
}],
opts = pulumi.ResourceOptions(depends_on=[test_attach]))
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var example = Aws.Ec2.GetSubnets.Invoke(new()
{
Filters = new[]
{
new Aws.Ec2.Inputs.GetSubnetsFilterInputArgs
{
Name = "vpc-id",
Values = new[]
{
vpcId,
},
},
},
});
var foo = new Aws.Ec2.LaunchTemplate("foo", new()
{
Name = "launch-template",
ImageId = "ami-516b9131",
InstanceType = "m1.small",
KeyName = "some-key",
});
var fooSpotFleetRequest = new Aws.Ec2.SpotFleetRequest("foo", new()
{
IamFleetRole = "arn:aws:iam::12345678:role/spot-fleet",
SpotPrice = "0.005",
TargetCapacity = 2,
ValidUntil = "2019-11-04T20:44:20Z",
LaunchTemplateConfigs = new[]
{
new Aws.Ec2.Inputs.SpotFleetRequestLaunchTemplateConfigArgs
{
LaunchTemplateSpecification = new Aws.Ec2.Inputs.SpotFleetRequestLaunchTemplateConfigLaunchTemplateSpecificationArgs
{
Id = foo.Id,
Version = foo.LatestVersion,
},
Overrides = new[]
{
new Aws.Ec2.Inputs.SpotFleetRequestLaunchTemplateConfigOverrideArgs
{
SubnetId = example.Apply(getSubnetsResult => getSubnetsResult.Ids[0]),
},
new Aws.Ec2.Inputs.SpotFleetRequestLaunchTemplateConfigOverrideArgs
{
SubnetId = example.Apply(getSubnetsResult => getSubnetsResult.Ids[1]),
},
new Aws.Ec2.Inputs.SpotFleetRequestLaunchTemplateConfigOverrideArgs
{
SubnetId = example.Apply(getSubnetsResult => getSubnetsResult.Ids[2]),
},
},
},
},
}, new CustomResourceOptions
{
DependsOn =
{
test_attach,
},
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
example, err := ec2.GetSubnets(ctx, &ec2.GetSubnetsArgs{
Filters: []ec2.GetSubnetsFilter{
{
Name: "vpc-id",
Values: interface{}{
vpcId,
},
},
},
}, nil);
if err != nil {
return err
}
foo, err := ec2.NewLaunchTemplate(ctx, "foo", &ec2.LaunchTemplateArgs{
Name: pulumi.String("launch-template"),
ImageId: pulumi.String("ami-516b9131"),
InstanceType: pulumi.String("m1.small"),
KeyName: pulumi.String("some-key"),
})
if err != nil {
return err
}
_, err = ec2.NewSpotFleetRequest(ctx, "foo", &ec2.SpotFleetRequestArgs{
IamFleetRole: pulumi.String("arn:aws:iam::12345678:role/spot-fleet"),
SpotPrice: pulumi.String("0.005"),
TargetCapacity: pulumi.Int(2),
ValidUntil: pulumi.String("2019-11-04T20:44:20Z"),
LaunchTemplateConfigs: ec2.SpotFleetRequestLaunchTemplateConfigArray{
&ec2.SpotFleetRequestLaunchTemplateConfigArgs{
LaunchTemplateSpecification: &ec2.SpotFleetRequestLaunchTemplateConfigLaunchTemplateSpecificationArgs{
Id: foo.ID(),
Version: foo.LatestVersion,
},
Overrides: ec2.SpotFleetRequestLaunchTemplateConfigOverrideArray{
&ec2.SpotFleetRequestLaunchTemplateConfigOverrideArgs{
SubnetId: pulumi.String(example.Ids[0]),
},
&ec2.SpotFleetRequestLaunchTemplateConfigOverrideArgs{
SubnetId: pulumi.String(example.Ids[1]),
},
&ec2.SpotFleetRequestLaunchTemplateConfigOverrideArgs{
SubnetId: pulumi.String(example.Ids[2]),
},
},
},
},
}, pulumi.DependsOn([]pulumi.Resource{
test_attach,
}))
if err != nil {
return err
}
return nil
})
}
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.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.List;
import java.util.ArrayList;
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()
.iamFleetRole("arn:aws:iam::12345678:role/spot-fleet")
.spotPrice("0.005")
.targetCapacity(2)
.validUntil("2019-11-04T20:44:20Z")
.launchTemplateConfigs(SpotFleetRequestLaunchTemplateConfigArgs.builder()
.launchTemplateSpecification(SpotFleetRequestLaunchTemplateConfigLaunchTemplateSpecificationArgs.builder()
.id(foo.id())
.version(foo.latestVersion())
.build())
.overrides(
SpotFleetRequestLaunchTemplateConfigOverrideArgs.builder()
.subnetId(example.applyValue(getSubnetsResult -> getSubnetsResult.ids()[0]))
.build(),
SpotFleetRequestLaunchTemplateConfigOverrideArgs.builder()
.subnetId(example.applyValue(getSubnetsResult -> getSubnetsResult.ids()[1]))
.build(),
SpotFleetRequestLaunchTemplateConfigOverrideArgs.builder()
.subnetId(example.applyValue(getSubnetsResult -> getSubnetsResult.ids()[2]))
.build())
.build())
.build(), CustomResourceOptions.builder()
.dependsOn(test_attach)
.build());
}
}
resources:
foo:
type: aws:ec2:LaunchTemplate
properties:
name: launch-template
imageId: ami-516b9131
instanceType: m1.small
keyName: some-key
fooSpotFleetRequest:
type: aws:ec2:SpotFleetRequest
name: foo
properties:
iamFleetRole: arn:aws:iam::12345678:role/spot-fleet
spotPrice: '0.005'
targetCapacity: 2
validUntil: 2019-11-04T20:44:20Z
launchTemplateConfigs:
- launchTemplateSpecification:
id: ${foo.id}
version: ${foo.latestVersion}
overrides:
- subnetId: ${example.ids[0]}
- subnetId: ${example.ids[1]}
- subnetId: ${example.ids[2]}
options:
dependsOn:
- ${["test-attach"]}
variables:
example:
fn::invoke:
function: aws:ec2:getSubnets
arguments:
filters:
- name: vpc-id
values:
- ${vpcId}

Import

Using pulumi import, import Spot Fleet Requests using id. For example:

$ pulumi import aws:ec2/spotFleetRequest:SpotFleetRequest fleet sfr-005e9ec8-5546-4c31-b317-31a62325411e

Constructors

Link copied to clipboard
constructor(allocationStrategy: Output<String>? = null, context: Output<String>? = null, excessCapacityTerminationPolicy: Output<String>? = null, fleetType: Output<String>? = null, iamFleetRole: Output<String>? = null, instanceInterruptionBehaviour: Output<String>? = null, instancePoolsToUseCount: Output<Int>? = null, launchSpecifications: Output<List<SpotFleetRequestLaunchSpecificationArgs>>? = null, launchTemplateConfigs: Output<List<SpotFleetRequestLaunchTemplateConfigArgs>>? = null, loadBalancers: Output<List<String>>? = null, onDemandAllocationStrategy: Output<String>? = null, onDemandMaxTotalPrice: Output<String>? = null, onDemandTargetCapacity: Output<Int>? = null, replaceUnhealthyInstances: Output<Boolean>? = null, spotMaintenanceStrategies: Output<SpotFleetRequestSpotMaintenanceStrategiesArgs>? = null, spotPrice: Output<String>? = null, tags: Output<Map<String, String>>? = null, targetCapacity: Output<Int>? = null, targetCapacityUnitType: Output<String>? = null, targetGroupArns: Output<List<String>>? = null, terminateInstancesOnDelete: Output<String>? = null, terminateInstancesWithExpiration: Output<Boolean>? = null, validFrom: Output<String>? = null, validUntil: Output<String>? = null, waitForFulfillment: Output<Boolean>? = null)

Properties

Link copied to clipboard
val allocationStrategy: Output<String>? = null

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.

Link copied to clipboard
val context: Output<String>? = null

Reserved.

Link copied to clipboard

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.

Link copied to clipboard
val fleetType: Output<String>? = null

The type of fleet request. Indicates whether the Spot Fleet only requests the target capacity or also attempts to maintain it. Default is maintain.

Link copied to clipboard
val iamFleetRole: Output<String>? = null

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.

Link copied to clipboard

Indicates whether a Spot instance stops or terminates when it is interrupted. Default is terminate.

Link copied to clipboard
val instancePoolsToUseCount: Output<Int>? = null

The number of Spot pools across which to allocate your target Spot capacity. Valid only when allocation_strategy 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.

Link copied to clipboard

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 launch_template_config. At least one of launch_specification or launch_template_config 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. Any normal aws.ec2.Instance parameter that corresponds to those inputs may be used and it have a additional parameter iam_instance_profile_arn takes aws.iam.InstanceProfile attribute arn as input.

Link copied to clipboard

Launch template configuration block. See Launch Template Configs below for more details. Conflicts with launch_specification. At least one of launch_specification or launch_template_config is required.

Link copied to clipboard
val loadBalancers: Output<List<String>>? = null

A list of elastic load balancer names to add to the Spot fleet.

Link copied to clipboard
val onDemandAllocationStrategy: Output<String>? = null

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.

Link copied to clipboard
val onDemandMaxTotalPrice: Output<String>? = null

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.

Link copied to clipboard
val onDemandTargetCapacity: Output<Int>? = null

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.

Link copied to clipboard
val replaceUnhealthyInstances: Output<Boolean>? = null

Indicates whether Spot fleet should replace unhealthy instances. Default false.

Link copied to clipboard

Nested argument containing maintenance strategies for managing your Spot Instances that are at an elevated risk of being interrupted. Defined below.

Link copied to clipboard
val spotPrice: Output<String>? = null

The maximum bid price per unit hour.

Link copied to clipboard
val tags: Output<Map<String, String>>? = null

A map of tags to assign to the resource. .If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.

Link copied to clipboard
val targetCapacity: Output<Int>? = null

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.

Link copied to clipboard
val targetCapacityUnitType: Output<String>? = null

The unit for the target capacity. This can only be done with instance_requirements defined

Link copied to clipboard
val targetGroupArns: Output<List<String>>? = null

A list of aws.alb.TargetGroup ARNs, for use with Application Load Balancing.

Link copied to clipboard
val terminateInstancesOnDelete: Output<String>? = null

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 terminate_instances_with_expiration argument is used.

Link copied to clipboard

Indicates whether running Spot instances should be terminated when the Spot fleet request expires.

Link copied to clipboard
val validFrom: Output<String>? = null

The start date and time of the request, in UTC RFC3339 format(for example, YYYY-MM-DDTHH:MM:SSZ). The default is to start fulfilling the request immediately.

Link copied to clipboard
val validUntil: Output<String>? = null

The end date and time of the request, in UTC RFC3339 format(for example, YYYY-MM-DDTHH:MM:SSZ). At this point, no new Spot instance requests are placed or enabled to fulfill the request.

Link copied to clipboard
val waitForFulfillment: Output<Boolean>? = null

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.

Functions

Link copied to clipboard
open override fun toJava(): SpotFleetRequestArgs