Skip to content

Resource: awsEc2Fleet

Provides a resource to manage EC2 Fleets.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.ec2Fleet.Ec2Fleet(this, "example", {
  launchTemplateConfig: [
    {
      launchTemplateSpecification: {
        launchTemplateId: "${aws_launch_template.example.id}",
        version: "${aws_launch_template.example.latest_version}",
      },
    },
  ],
  targetCapacitySpecification: {
    defaultTargetCapacityType: "spot",
    totalTargetCapacity: 5,
  },
});

Argument Reference

The following arguments are supported:

  • context - (Optional) Reserved.
  • excessCapacityTerminationPolicy - (Optional) Whether running instances should be terminated if the total target capacity of the EC2 Fleet is decreased below the current size of the EC2. Valid values: noTermination, termination. Defaults to termination. Supported only for fleets of type maintain.
  • launchTemplateConfig - (Required) Nested argument containing EC2 Launch Template configurations. Defined below.
  • onDemandOptions - (Optional) Nested argument containing On-Demand configurations. Defined below.
  • replaceUnhealthyInstances - (Optional) Whether EC2 Fleet should replace unhealthy instances. Defaults to false. Supported only for fleets of type maintain.
  • spotOptions - (Optional) Nested argument containing Spot configurations. Defined below.
  • tags - (Optional) Map of Fleet tags. To tag instances at launch, specify the tags in the Launch Template. If configured with a provider defaultTags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
  • targetCapacitySpecification - (Required) Nested argument containing target capacity configurations. Defined below.
  • terminateInstances - (Optional) Whether to terminate instances for an EC2 Fleet if it is deleted successfully. Defaults to false.
  • terminateInstancesWithExpiration - (Optional) Whether running instances should be terminated when the EC2 Fleet expires. Defaults to false.
  • type - (Optional) The type of request. Indicates whether the EC2 Fleet only requests the target capacity, or also attempts to maintain it. Valid values: maintain, request, instant. Defaults to maintain.
  • validFrom - (Optional) The start date and time of the request, in UTC format (for example, YYYY-MM-DDTHH:MM:SSZ). The default is to start fulfilling the request immediately.
  • validUntil - (Optional) The end date and time of the request, in UTC format (for example, YYYY-MM-DDTHH:MM:SSZ). At this point, no new EC2 Fleet requests are placed or able to fulfill the request. If no value is specified, the request remains until you cancel it.

launchTemplateConfig

Describes a launch template and overrides.

  • launchTemplateSpecification - (Optional) Nested argument containing EC2 Launch Template to use. Defined below.
  • override - (Optional) Nested argument(s) containing parameters to override the same parameters in the Launch Template. Defined below.

launchTemplateSpecification

The launch template to use. You must specify either the launch template ID or launch template name in the request.

  • launchTemplateId - (Optional) The ID of the launch template.
  • launchTemplateName - (Optional) The name of the launch template.
  • version - (Required) The launch template version number, $latest, or $default

override

Any parameters that you specify override the same parameters in the launch template. For fleets of type request and maintain, a maximum of 300 items is allowed across all launch templates.

Example:

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.ec2Fleet.Ec2Fleet(this, "example", {
  launchTemplateConfig: [
    {
      override: [
        {
          instanceType: "m4.xlarge",
          weightedCapacity: 1,
        },
        {
          instanceType: "m4.2xlarge",
          weightedCapacity: 2,
        },
      ],
    },
  ],
});
  • availabilityZone - (Optional) Availability Zone in which to launch the instances.
  • instanceRequirements - (Optional) Override the instance type in the Launch Template with instance types that satisfy the requirements.
  • instanceType - (Optional) Instance type.
  • maxPrice - (Optional) Maximum price per unit hour that you are willing to pay for a Spot Instance.
  • priority - (Optional) Priority for the launch template override. If onDemandOptions allocationStrategy is set to prioritized, EC2 Fleet uses priority to determine which launch template override to use first in fulfilling On-Demand capacity. The highest priority is launched first. The lower the number, the higher the priority. If no number is set, the launch template override has the lowest priority. Valid values are whole numbers starting at 0.
  • subnetId - (Optional) ID of the subnet in which to launch the instances.
  • weightedCapacity - (Optional) Number of units provided by the specified instance type.
instanceRequirements

The attributes for the instance types. For a list of currently supported values, please see 'InstanceRequirementsRequest'.

This configuration block supports the following:

\~> NOTE: Both memoryMibMin and vcpuCountMin must be specified.

  • acceleratorCount - (Optional) Block describing the minimum and maximum number of accelerators (GPUs, FPGAs, or AWS Inferentia chips). Default is no minimum or maximum limits.

    • min - (Optional) Minimum.
    • max - (Optional) Maximum. Set to 0 to exclude instance types with accelerators.
  • acceleratorManufacturers - (Optional) List of accelerator manufacturer names. Default is any manufacturer.

  • acceleratorNames - (Optional) List of accelerator names. Default is any acclerator.

  • acceleratorTotalMemoryMib - (Optional) Block describing the minimum and maximum total memory of the accelerators. Default is no minimum or maximum.

    • min - (Optional) The minimum amount of accelerator memory, in MiB. To specify no minimum limit, omit this parameter.
    • max - (Optional) The maximum amount of accelerator memory, in MiB. To specify no maximum limit, omit this parameter.
  • acceleratorTypes - (Optional) The accelerator types that must be on the instance type. Default is any accelerator type.

  • allowedInstanceTypes - (Optional) The instance types to apply your specified attributes against. All other instance types are ignored, even if they match your specified attributes. You can use strings with one or more wild cards,represented by an asterisk (*). The following are examples: c5*, m5A.*, r*, *3*. For example, if you specify c5*, you are excluding the entire C5 instance family, which includes all C5a and C5n instance types. If you specify m5A.*, you are excluding all the M5a instance types, but not the M5n instance types. Maximum of 400 entries in the list; each entry is limited to 30 characters. Default is no excluded instance types. Default is any instance type.

    If you specify allowedInstanceTypes, you can't specify excludedInstanceTypes.

  • bareMetal - (Optional) Indicate whether bare metal instace types should be included, excluded, or required. Default is excluded.

  • baselineEbsBandwidthMbps - (Optional) Block describing the minimum and maximum baseline EBS bandwidth, in Mbps. Default is no minimum or maximum.

    • min - (Optional) The minimum baseline bandwidth, in Mbps. To specify no minimum limit, omit this parameter..
    • max - (Optional) The maximum baseline bandwidth, in Mbps. To specify no maximum limit, omit this parameter..
  • burstablePerformance - (Optional) Indicates whether burstable performance T instance types are included, excluded, or required. Default is excluded.

  • cpuManufacturers (Optional) The CPU manufacturers to include. Default is any manufacturer. \~> NOTE: Don't confuse the CPU hardware manufacturer with the CPU hardware architecture. Instances will be launched with a compatible CPU architecture based on the Amazon Machine Image (AMI) that you specify in your launch template.

  • excludedInstanceTypes - (Optional) The instance types to exclude. You can use strings with one or more wild cards, represented by an asterisk (*). The following are examples: c5*, m5A.*, r*, *3*. For example, if you specify c5*, you are excluding the entire C5 instance family, which includes all C5a and C5n instance types. If you specify m5A.*, you are excluding all the M5a instance types, but not the M5n instance types. Maximum of 400 entries in the list; each entry is limited to 30 characters. Default is no excluded instance types.

    If you specify allowedInstanceTypes, you can't specify excludedInstanceTypes.

  • instanceGenerations - (Optional) Indicates whether current or previous generation instance types are included. The current generation instance types are recommended for use. Valid values are current and previous. Default is current and previous generation instance types.

  • localStorage - (Optional) Indicate whether instance types with local storage volumes are included, excluded, or required. Default is included.

  • localStorageTypes - (Optional) List of local storage type names. Valid values are hdd and ssd. Default any storage type.

  • memoryGibPerVcpu - (Optional) Block describing the minimum and maximum amount of memory (GiB) per vCPU. Default is no minimum or maximum.

    • min - (Optional) The minimum amount of memory per vCPU, in GiB. To specify no minimum limit, omit this parameter.
    • max - (Optional) The maximum amount of memory per vCPU, in GiB. To specify no maximum limit, omit this parameter.
  • memoryMib - (Required) The minimum and maximum amount of memory per vCPU, in GiB. Default is no minimum or maximum limits.

    • min - (Required) The minimum amount of memory, in MiB. To specify no minimum limit, specify 0.
    • max - (Optional) The maximum amount of memory, in MiB. To specify no maximum limit, omit this parameter.
  • networkBandwidthGbps - (Optional) The minimum and maximum amount of network bandwidth, in gigabits per second (Gbps). Default is No minimum or maximum.

    • min - (Optional) The minimum amount of network bandwidth, in Gbps. To specify no minimum limit, omit this parameter.
    • max - (Optional) The maximum amount of network bandwidth, in Gbps. To specify no maximum limit, omit this parameter.
  • networkInterfaceCount - (Optional) Block describing the minimum and maximum number of network interfaces. Default is no minimum or maximum.

    • min - (Optional) The minimum number of network interfaces. To specify no minimum limit, omit this parameter.
    • max - (Optional) The maximum number of network interfaces. To specify no maximum limit, omit this parameter.
  • onDemandMaxPricePercentageOverLowestPrice - (Optional) The price protection threshold for On-Demand Instances. This is the maximum you’ll pay for an On-Demand Instance, expressed as a percentage higher than the cheapest M, C, or R instance type with your specified attributes. When Amazon EC2 Auto Scaling selects instance types with your attributes, we will exclude instance types whose price is higher than your threshold. The parameter accepts an integer, which Amazon EC2 Auto Scaling interprets as a percentage. To turn off price protection, specify a high value, such as 999999. Default is 20.

    If you set targetCapacityUnitType to vcpu or memoryMib, the price protection threshold is applied based on the per-vCPU or per-memory price instead of the per-instance price.

  • requireHibernateSupport - (Optional) Indicate whether instance types must support On-Demand Instance Hibernation, either true or false. Default is false.

  • spotMaxPricePercentageOverLowestPrice - (Optional) The price protection threshold for Spot Instances. This is the maximum you’ll pay for a Spot Instance, expressed as a percentage higher than the cheapest M, C, or R instance type with your specified attributes. When Amazon EC2 Auto Scaling selects instance types with your attributes, we will exclude instance types whose price is higher than your threshold. The parameter accepts an integer, which Amazon EC2 Auto Scaling interprets as a percentage. To turn off price protection, specify a high value, such as 999999. Default is 100.

    If you set DesiredCapacityType to vcpu or memory-mib, the price protection threshold is applied based on the per vCPU or per memory price instead of the per instance price.

  • totalLocalStorageGb - (Optional) Block describing the minimum and maximum total local storage (GB). Default is no minimum or maximum.

    • min - (Optional) The minimum amount of total local storage, in GB. To specify no minimum limit, omit this parameter.
    • max - (Optional) The maximum amount of total local storage, in GB. To specify no maximum limit, omit this parameter.
  • vcpuCount - (Required) Block describing the minimum and maximum number of vCPUs. Default is no maximum.

    • min - (Required) The minimum number of vCPUs. To specify no minimum limit, specify 0.
    • max - (Optional) The maximum number of vCPUs. To specify no maximum limit, omit this parameter.

onDemandOptions

  • allocationStrategy - (Optional) The order of the launch template overrides to use in fulfilling On-Demand capacity. Valid values: lowestPrice, prioritized. Default: lowestPrice.

  • capacityReservationOptions (Optional) The strategy for using unused Capacity Reservations for fulfilling On-Demand capacity. Supported only for fleets of type instant.

    • usageStrategy - (Optional) Indicates whether to use unused Capacity Reservations for fulfilling On-Demand capacity. Valid values: useCapacityReservationsFirst.
  • maxTotalPrice - (Optional) The maximum amount per hour for On-Demand Instances that you're willing to pay.

  • minTargetCapacity - (Optional) The minimum target capacity for On-Demand Instances in the fleet. If the minimum target capacity is not reached, the fleet launches no instances. Supported only for fleets of type instant. If you specify minTargetCapacity, at least one of the following must be specified: singleAvailabilityZone or singleInstanceType.

  • singleAvailabilityZone - (Optional) Indicates that the fleet launches all On-Demand Instances into a single Availability Zone. Supported only for fleets of type instant.

  • singleInstanceType - (Optional) Indicates that the fleet uses a single instance type to launch all On-Demand Instances in the fleet. Supported only for fleets of type instant.

spotOptions

  • allocationStrategy - (Optional) How to allocate the target capacity across the Spot pools. Valid values: diversified, lowestPrice, capacityOptimized, capacityOptimizedPrioritized and priceCapacityOptimized. Default: lowestPrice.
  • instanceInterruptionBehavior - (Optional) Behavior when a Spot Instance is interrupted. Valid values: hibernate, stop, terminate. Default: terminate.
  • instancePoolsToUseCount - (Optional) Number of Spot pools across which to allocate your target Spot capacity. Valid only when Spot allocationStrategy is set to lowestPrice. Default: 1.
  • maintenanceStrategies - (Optional) Nested argument containing maintenance strategies for managing your Spot Instances that are at an elevated risk of being interrupted. Defined below.
  • maxTotalPrice - (Optional) The maximum amount per hour for Spot Instances that you're willing to pay.
  • minTargetCapacity - (Optional) The minimum target capacity for Spot Instances in the fleet. If the minimum target capacity is not reached, the fleet launches no instances. Supported only for fleets of type instant.
  • singleAvailabilityZone - (Optional) Indicates that the fleet launches all Spot Instances into a single Availability Zone. Supported only for fleets of type instant.
  • singleInstanceType - (Optional) Indicates that the fleet uses a single instance type to launch all Spot Instances in the fleet. Supported only for fleets of type instant.

maintenanceStrategies

  • capacityRebalance - (Optional) Nested argument containing the capacity rebalance for your fleet request. Defined below.

capacityRebalance

  • replacementStrategy - (Optional) The replacement strategy to use. Only available for fleets of type set to maintain. Valid values: launch.

targetCapacitySpecification

  • defaultTargetCapacityType - (Required) Default target capacity type. Valid values: onDemand, spot.

  • onDemandTargetCapacity - (Optional) The number of On-Demand units to request.

  • spotTargetCapacity - (Optional) The number of Spot units to request.

  • targetCapacityUnitType - (Optional) The unit for the target capacity. If you specify targetCapacityUnitType, instanceRequirements must be specified.

  • totalTargetCapacity - (Required) The number of units to request, filled using defaultTargetCapacityType.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • id - Fleet identifier
  • arn - The ARN of the fleet
  • fleetInstanceSet - Information about the instances that were launched by the fleet. Available only when type is set to instant.
  • instanceIds - The IDs of the instances.
  • instanceType - The instance type.
  • lifecycle - Indicates if the instance that was launched is a Spot Instance or On-Demand Instance.
  • platform - The value is windows for Windows instances. Otherwise, the value is blank.
  • fleetState - The state of the EC2 Fleet.
  • fulfilledCapacity - The number of units fulfilled by this request compared to the set target capacity.
  • fulfilledOnDemandCapacity - The number of units fulfilled by this request compared to the set target On-Demand capacity.
  • tagsAll - A map of tags assigned to the resource, including those inherited from the provider defaultTags configuration block.

Timeouts

Configuration options:

  • create - (Default 10M)
  • update - (Default 10M)
  • delete - (Default 10M)

Import

awsEc2Fleet can be imported by using the Fleet identifier, e.g.,

$ terraform import aws_ec2_fleet.example fleet-b9b55d27-c5fc-41ac-a6f3-48fcc91f080c