SpotInstanceRequest class

Provides an EC2 Spot Instance Request resource. This allows instances to be requested on the spot market.

By default this provider creates Spot Instance Requests with a persistent type, which means that for the duration of their lifetime, AWS will launch an instance with the configured details if and when the spot market will accept the requested price.

On destruction, this provider will make an attempt to terminate the associated Spot Instance if there is one present.

Spot Instances requests with a one-time type will close the spot request when the instance is terminated either by the request being below the current spot price availability or by a user.

> NOTE: Because their behavior depends on the live status of the spot market, Spot Instance Requests have a unique lifecycle that makes them behave differently than other Terraform resources. Most importantly: there is no guarantee that a Spot Instance exists to fulfill the request at any given point in time. See the AWS Spot Instance documentation for more information.

> **NOTE AWS strongly discourages the use of the legacy APIs called by this resource. We recommend using the EC2 Instance resource with instanceMarketOptions instead.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

// Request a spot instance at $0.03
const cheapWorker = new aws.ec2.SpotInstanceRequest("cheap_worker", {
    ami: "ami-1234",
    spotPrice: "0.03",
    instanceType: "c4.xlarge",
    tags: {
        Name: "CheapWorker",
    },
});
import pulumi
import pulumi_aws as aws

# Request a spot instance at $0.03
cheap_worker = aws.ec2.SpotInstanceRequest("cheap_worker",
    ami="ami-1234",
    spot_price="0.03",
    instance_type="c4.xlarge",
    tags={
        "Name": "CheapWorker",
    })
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() =>
{
    // Request a spot instance at $0.03
    var cheapWorker = new Aws.Ec2.SpotInstanceRequest("cheap_worker", new()
    {
        Ami = "ami-1234",
        SpotPrice = "0.03",
        InstanceType = "c4.xlarge",
        Tags =
        {
            { "Name", "CheapWorker" },
        },
    });

});
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/ec2"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		// Request a spot instance at $0.03
		_, err := ec2.NewSpotInstanceRequest(ctx, "cheap_worker", &ec2.SpotInstanceRequestArgs{
			Ami:          pulumi.String("ami-1234"),
			SpotPrice:    pulumi.String("0.03"),
			InstanceType: pulumi.String("c4.xlarge"),
			Tags: pulumi.StringMap{
				"Name": pulumi.String("CheapWorker"),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

# Request a spot instance at $0.03
resource "aws_ec2_spotinstancerequest" "cheap_worker" {
  ami           = "ami-1234"
  spot_price    = "0.03"
  instance_type = "c4.xlarge"
  tags = {
    "Name" = "CheapWorker"
  }
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.SpotInstanceRequest;
import com.pulumi.aws.ec2.SpotInstanceRequestArgs;
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 instance at $0.03
        var cheapWorker = new SpotInstanceRequest("cheapWorker", SpotInstanceRequestArgs.builder()
            .ami("ami-1234")
            .spotPrice("0.03")
            .instanceType("c4.xlarge")
            .tags(Map.of("Name", "CheapWorker"))
            .build());

    }
}
resources:
  # Request a spot instance at $0.03
  cheapWorker:
    type: aws:ec2:SpotInstanceRequest
    name: cheap_worker
    properties:
      ami: ami-1234
      spotPrice: '0.03'
      instanceType: c4.xlarge
      tags:
        Name: CheapWorker

Constructors

SpotInstanceRequest(String name, {SpotInstanceRequestArgs? args, CustomResourceOptions? options})
Creates a new SpotInstanceRequest. name The Pulumi resource name. args Arguments used to configure this SpotInstanceRequest. The set of arguments for SpotInstanceRequest. options Resource options controlling this resource's behavior.
SpotInstanceRequest.reference(String urn)
Creates a typed reference to an existing SpotInstanceRequest resource.

Properties

ami ↔ Output<String>
AMI to use for the instance. Required unless launchTemplate is specified and the Launch Template specifes an AMI. If an AMI is specified in the Launch Template, setting ami will override the AMI specified in the Launch Template.
latefinal
arn ↔ Output<String>
latefinal
associatePublicIpAddress ↔ Output<bool>
Whether to associate a public IP address with an instance in a VPC.
latefinal
availabilityZone ↔ Output<String>
AZ to start the instance in.
latefinal
capacityReservationSpecification ↔ Output<SpotInstanceRequestCapacityReservationSpecification>
Describes an instance's Capacity Reservation targeting option. See Capacity Reservation Specification below for more details.
latefinal
childResources → Set<Resource>
finalinherited
completionSources ↔ Map<String, IOutputCompletionSource>
latefinalinherited
cpuOptions ↔ Output<SpotInstanceRequestCpuOptions>
The CPU options for the instance. See CPU Options below for more details.
latefinal
creditSpecification ↔ Output<SpotInstanceRequestCreditSpecification?>
Configuration block for customizing the credit specification of the instance. See Credit Specification below for more details. This provider will only perform drift detection of its value when present in a configuration. Removing this configuration on existing instances will only stop managing it. It will not change the configuration back to the default for the instance type.
latefinal
disableApiStop ↔ Output<bool>
If true, enables EC2 Instance Stop Protection.
latefinal
disableApiTermination ↔ Output<bool>
If true, enables EC2 Instance Termination Protection.
latefinal
ebsBlockDevices ↔ Output<List<SpotInstanceRequestEbsBlockDevice>>
One or more configuration blocks with additional EBS block devices to attach to the instance. Block device configurations only apply on resource creation. See Block Devices below for details on attributes and drift detection. When accessing this as an attribute reference, it is a set of objects.
latefinal
ebsOptimized ↔ Output<bool>
If true, the launched EC2 instance will be EBS-optimized. Note that if this is not set on an instance type that is optimized by default then this will show as disabled but if the instance type is optimized by default then there is no need to set this and there is no effect to disabling it. See the EBS Optimized section of the AWS User Guide for more information.
latefinal
enablePrimaryIpv6 ↔ Output<bool>
Whether to assign a primary IPv6 Global Unicast Address (GUA) to the instance when launched in a dual-stack or IPv6-only subnet. A primary IPv6 address ensures a consistent IPv6 address for the instance and is automatically assigned by AWS to the ENI. Once enabled, the first IPv6 GUA becomes the primary IPv6 address and cannot be disabled. The primary IPv6 address remains until the instance is terminated or the ENI is detached. Disabling enablePrimaryIpv6 after it has been enabled forces recreation of the instance.
latefinal
enclaveOptions ↔ Output<SpotInstanceRequestEnclaveOptions>
Enable Nitro Enclaves on launched instances. See Enclave Options below for more details.
latefinal
ephemeralBlockDevices ↔ Output<List<SpotInstanceRequestEphemeralBlockDevice>>
One or more configuration blocks to customize Ephemeral (also known as "Instance Store") volumes on the instance. See Block Devices below for details. When accessing this as an attribute reference, it is a set of objects.
latefinal
forceDestroy ↔ Output<bool?>
Destroys instance even if disableApiTermination or disableApiStop is set to true. Defaults to false. Once this parameter is set to true, a successful pulumi up run before a destroy is required to update this value in the resource state. Without a successful pulumi up after this parameter is set, this flag will have no effect. If setting this field in the same operation that would require replacing the instance or destroying the instance, this flag will not work. Additionally when importing an instance, a successful pulumi up is required to set this value in state before it will take effect on a destroy operation.
latefinal
getPasswordData ↔ Output<bool?>
If true, wait for password data to become available and retrieve it. Useful for getting the administrator password for instances running Microsoft Windows. The password data is exported to the passwordData attribute. See GetPasswordData for more information.
latefinal
hashCode → int
The hash code for this object.
no setterinherited
hibernation ↔ Output<bool?>
If true, the launched EC2 instance will support hibernation.
latefinal
hostId ↔ Output<String>
ID of a dedicated host that the instance will be assigned to. Use when an instance is to be launched on a specific dedicated host.
latefinal
hostResourceGroupArn ↔ Output<String>
ARN of the host resource group in which to launch the instances. If you specify an ARN, omit the tenancy parameter or set it to host.
latefinal
iamInstanceProfile ↔ Output<String>
IAM Instance Profile to launch the instance with. Specified as the name of the Instance Profile. Ensure your credentials have the correct permission to assign the instance profile according to the EC2 documentation, notably iam:PassRole.
latefinal
id ↔ Output<String>
getter/setter pairinherited
instanceInitiatedShutdownBehavior ↔ Output<String>
Shutdown behavior for the instance. Amazon defaults this to stop for EBS-backed instances and terminate for instance-store instances. Cannot be set on instance-store instances. See Shutdown Behavior for more information.
latefinal
instanceInterruptionBehavior ↔ Output<String?>
Indicates Spot instance behavior when it is interrupted. Valid values are terminate, stop, or hibernate. Default value is terminate.
latefinal
instanceState ↔ Output<String>
latefinal
instanceType ↔ Output<String>
Instance type to use for the instance. Required unless launchTemplate is specified and the Launch Template specifies an instance type. If an instance type is specified in the Launch Template, setting instanceType will override the instance type specified in the Launch Template. Updates to this field will trigger a stop/start of the EC2 instance.
latefinal
ipv6AddressCount ↔ Output<int>
Number of IPv6 addresses to associate with the primary network interface. Amazon EC2 chooses the IPv6 addresses from the range of your subnet.
latefinal
ipv6Addresses ↔ Output<List<String>>
Specify one or more IPv6 addresses from the range of the subnet to associate with the primary network interface
latefinal
isCustom → bool
Returns whether this resource is provider-managed.
no setterinherited
isProtected → bool
Returns whether this resource is protected from deletion.
no setterinherited
isRemote → bool
Whether this resource is registered as remote.
no setterinherited
isResourceReference → bool
Whether this instance represents a resource value returned over RPC.
finalinherited
keyName ↔ Output<String>
Key name of the Key Pair to use for the instance; which can be managed using the aws.ec2.KeyPair resource.
latefinal
launchGroup ↔ Output<String?>
A launch group is a group of spot instances that launch together and terminate together. If left empty instances are launched and terminated individually.
latefinal
launchTemplate ↔ Output<SpotInstanceRequestLaunchTemplate?>
Specifies a Launch Template to configure the instance. Parameters configured on this resource will override the corresponding parameters in the Launch Template. See Launch Template Specification below for more details.
latefinal
maintenanceOptions ↔ Output<SpotInstanceRequestMaintenanceOptions>
Maintenance and recovery options for the instance. See Maintenance Options below for more details.
latefinal
metadataOptions ↔ Output<SpotInstanceRequestMetadataOptions>
Customize the metadata options of the instance. See Metadata Options below for more details.
latefinal
monitoring ↔ Output<bool>
If true, the launched EC2 instance will have detailed monitoring enabled. (Available since v0.6.0)
latefinal
networkInterfaces ↔ Output<List<SpotInstanceRequestNetworkInterface>>
Customize network interfaces to be attached at instance boot time. See Network Interfaces below for more details.
latefinal
outpostArn ↔ Output<String>
latefinal
passwordData ↔ Output<String>
latefinal
placementGroup ↔ Output<String>
Placement Group to start the instance in. Conflicts with placementGroupId.
latefinal
placementGroupId ↔ Output<String>
Placement Group ID to start the instance in. Conflicts with placementGroup.
latefinal
placementPartitionNumber ↔ Output<int>
Number of the partition the instance is in. Valid only if the aws.ec2.PlacementGroup resource's strategy argument is set to "partition".
latefinal
primaryNetworkInterfaceId ↔ Output<String>
latefinal
primaryNetworkInterfaces ↔ Output<List<SpotInstanceRequestPrimaryNetworkInterface>>
The primary network interface. See Primary Network Interface below.
latefinal
privateDns ↔ Output<String>
The private DNS name assigned to the instance. Can only be used inside the Amazon EC2, and only available if you've enabled DNS hostnames for your VPC
latefinal
privateDnsNameOptions ↔ Output<SpotInstanceRequestPrivateDnsNameOptions>
Options for the instance hostname. The default values are inherited from the subnet. See Private DNS Name Options below for more details.
latefinal
privateIp ↔ Output<String>
Private IP address to associate with the instance in a VPC.
latefinal
publicDns ↔ Output<String>
The public DNS name assigned to the instance. For EC2-VPC, this is only available if you've enabled DNS hostnames for your VPC
latefinal
publicIp ↔ Output<String>
The public IP address assigned to the instance, if applicable.
latefinal
region ↔ Output<String>
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
resourceTransforms → List<ResourceTransform>
Inherited/explicit async transforms.
no setterinherited
rootBlockDevice ↔ Output<SpotInstanceRequestRootBlockDevice>
Configuration block to customize details about the root block device of the instance. See Block Devices below for details. When accessing this as an attribute reference, it is a list containing one object.
latefinal
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
secondaryNetworkInterfaces ↔ Output<List<SpotInstanceRequestSecondaryNetworkInterface>>
One or more secondary network interfaces to attach to the instance at launch time. See Secondary Network Interface below for more details.
latefinal
secondaryPrivateIps ↔ Output<List<String>>
List of secondary private IPv4 addresses to assign to the instance's primary network interface (eth0) in a VPC. Can only be assigned to the primary network interface (eth0) attached at instance creation, not a pre-existing network interface i.e., referenced in a networkInterface block. Refer to the Elastic network interfaces documentation to see the maximum number of private IP addresses allowed per instance type.
latefinal
securityGroups ↔ Output<List<String>>
List of security group names to associate with.
latefinal
sourceDestCheck ↔ Output<bool?>
Controls if traffic is routed to the instance when the destination address does not match the instance. Used for NAT or VPNs. Defaults true.
latefinal
spotBidStatus ↔ Output<String>
The current bid status of the Spot Instance Request.
latefinal
spotInstanceId ↔ Output<String>
The Instance ID (if any) that is currently fulfilling the Spot Instance request.
latefinal
spotPrice ↔ Output<String>
The maximum price to request on the spot market.
latefinal
spotRequestState ↔ Output<String>
The current request state of the Spot Instance Request.
latefinal
spotType ↔ Output<String?>
If set to one-time, after the instance is terminated, the spot request will be closed.
latefinal
subnetId ↔ Output<String>
VPC Subnet ID to launch in.
latefinal
tags ↔ Output<Map<String, String>?>
Map of tags to assign to the resource. Note that these tags apply to the instance and not block storage devices. If configured with a provider defaultTags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
latefinal
tagsAll ↔ Output<Map<String, String>>
A map of tags assigned to the resource, including those inherited from the provider defaultTags configuration block.
latefinal
tenancy ↔ Output<String>
Tenancy of the instance (if the instance is running in a VPC). An instance with a tenancy of dedicated runs on single-tenant hardware. The host tenancy is not supported for the import-instance command. Valid values are default, dedicated, and host.
latefinal
transformations → List<ResourceTransformation>
Inherited/explicit legacy transformations.
no setterinherited
urn ↔ Output<String>
latefinalinherited
userData ↔ Output<String?>
User data to provide when launching the instance. Do not pass gzip-compressed data via this argument; see userDataBase64 instead. Updates to this field will trigger a stop/start of the EC2 instance by default. If the userDataReplaceOnChange is set then updates to this field will trigger a destroy and recreate of the EC2 instance.
latefinal
userDataBase64 ↔ Output<String>
Can be used instead of userData to pass base64-encoded binary data directly. Use this instead of userData whenever the value is not a valid UTF-8 string. For example, gzip-encoded user data must be base64-encoded and passed via this argument to avoid corruption. Updates to this field will trigger a stop/start of the EC2 instance by default. If the userDataReplaceOnChange is set then updates to this field will trigger a destroy and recreate of the EC2 instance.
latefinal
userDataReplaceOnChange ↔ Output<bool?>
When used in combination with userData or userDataBase64 will trigger a destroy and recreate of the EC2 instance when set to true. Defaults to false if not set.
latefinal
validFrom ↔ Output<String>
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.
latefinal
validUntil ↔ Output<String>
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. The default end date is 7 days from the current date.
latefinal
volumeTags ↔ Output<Map<String, String>?>
Map of tags to assign, at instance-creation time, to root and EBS volumes.
latefinal
vpcSecurityGroupIds ↔ Output<List<String>>
List of security group IDs to associate with.
latefinal
waitForFulfillment ↔ Output<bool?>
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.
latefinal

Methods

failId(Object error) → void
Completes this resource ID with an error when registration fails.
inherited
failOutputs(Object error) → void
Completes all output properties with error.
inherited
failUrn(Object error) → void
Completes this resource URN with an error when registration fails.
inherited
getProvider(String moduleMember) → ProviderResource?
Returns provider for moduleMember's package, if configured.
inherited
getResourceName() → String
Returns this resource's logical name.
inherited
getResourceType() → String
Returns this resource's Pulumi type token.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerOutput<T>(String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output<T>
Registers a dynamic output property for this resource.
inherited
resolveId(String? value, {required bool isKnown}) → void
Resolves the provider-assigned ID for this resource.
inherited
resolveOutputs(Struct outputs) → void
Resolves all output properties from a monitor response payload.
inherited
resolveUrn(String value) → void
Resolves this resource's URN once assigned by the engine.
inherited
serializeProperties(Map<String, dynamic> properties) → Future<Struct>
Serializes resource properties for RPC transmission.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

get(String name, Input<String> id, {SpotInstanceRequestState? state, CustomResourceOptions? options}) → SpotInstanceRequest
Gets an existing SpotInstanceRequest resource's state with the given name and id.