AWS Amazon EC2 Fleet Request

This page shows how to write Terraform and CloudFormation for Amazon EC2 Fleet Request and write them securely.

code-icon

Fix issues in your cloud & app configurations

Test for misconfigurations of this resource in your cloud.

get-started-button

Terraform Example (aws_spot_fleet_request)

Provides an EC2 Spot Fleet Request resource. This allows a fleet of Spot instances to be requested on the Spot market.

Parameters

Example Usage (from GitHub)

github-iconsolemnwarning/build-server-deployment
resource "aws_spot_fleet_request" "debian" {
  iam_fleet_role  = "arn:aws:iam::652694334613:role/aws-service-role/spotfleet.amazonaws.com/AWSServiceRoleForEC2SpotFleet"
  target_capacity = 0

  # terminate_instances = true
  terminate_instances_with_expiration = true
github-iconfdns/terraform-k8s
resource "aws_spot_fleet_request" "master_nodes" {
  iam_fleet_role                      = "arn:aws:iam::345025288683:role/aws-ec2-spot-fleet-tagging-role"
  spot_price                          = var.master_bid
  allocation_strategy                 = "lowestPrice"
  target_capacity                     = 1
  valid_until                         = timeadd(timestamp(), var.spot_time)
github-iconpmkuny/aws-env
resource "aws_spot_fleet_request" "test" {
  iam_fleet_role      = "arn:aws:iam::695507447459:role/aws-ec2-spot-fleet-tagging-role"
}

resource "aws_launch_template" "test_spot_fleet" {
  name_prefix = "spot-"
github-iconJamesWoolfenden/check-encrypt
resource "aws_spot_fleet_request" "test" {
  iam_fleet_role                      = aws_iam_role.test.arn
  spot_price                          = "0.05"
  target_capacity                     = 1
  terminate_instances_with_expiration = true
  valid_until                         = "01/01/2222"
github-icontokazaki42/terraform-examples
resource "aws_spot_fleet_request" "spot-ssm-example-spot-request" {
  iam_fleet_role = aws_iam_role.role.arn

  target_capacity                     = 1
  terminate_instances_with_expiration = true
  wait_for_fulfillment                = "true"

CloudFormation Example (AWS::EC2::SpotFleet)

Specifies a Spot Fleet request. A Spot Fleet request contains the configuration information to launch a fleet, or group, of instances.

The Spot Fleet request specifies the total target capacity and the On-Demand target capacity for the fleet. Amazon EC2 calculates the difference between the total capacity and On-Demand capacity, and launches the difference as Spot capacity.

The Spot Fleet request can include multiple launch specifications that vary by instance type, AMI, Availability Zone, or subnet.

By default, the Spot Fleet requests Spot Instances in the Spot pool where the price per unit is the lowest. Each launch specification can include its own instance weighting that reflects the value of the instance type to your application workload.

Alternatively, you can specify that the Spot Fleet distribute the target capacity across the Spot pools included in its launch specifications. By ensuring that the Spot Instances in your Spot Fleet are in different Spot pools, you can improve the availability of your fleet.

You can specify tags for the Spot Instances. You cannot tag other resource types in a Spot Fleet request because only the instance resource type is supported.

For more information, see Spot Fleet Requests in the Amazon EC2 User Guide for Linux Instances.

Parameters

Frequently asked questions

What is AWS Amazon EC2 Fleet Request?

AWS Amazon EC2 Fleet Request is a resource for Amazon EC2 of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS Amazon EC2 Fleet Request?

For Terraform, the solemnwarning/build-server-deployment, fdns/terraform-k8s and pmkuny/aws-env source code examples are useful. See the Terraform Example section for further details.