AWS Amazon EC2 Instance Request

This page shows how to write Terraform and CloudFormation for Amazon EC2 Instance 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_instance_request)

Provides an EC2 Spot Instance Request resource. This allows instances to be requested on the spot market. By default Terraform 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, Terraform 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.

Parameters

Example Usage (from GitHub)

github-iconggirault/poc-vpc-shared
resource "aws_spot_instance_request" "public" {
  ami                  = "ami-0b3e57ee3b63dd76b" # amazon linux 2 ami
  spot_price           = "0.03"
  instance_type        = "t3a.nano"
  subnet_id            = module.vpc.public_subnets[0]
  iam_instance_profile = aws_iam_instance_profile.main.id
github-iconAngelo512/Terabyte-CIT481-Senior-Project
resource "aws_spot_instance_request" "spot1" {
  ami                    = "ami-02701bcdc5509e57b"
  spot_price             = "0.016"
  instance_type          = "t2.micro"
  spot_type              = "one-time"
  wait_for_fulfillment   = "true"
github-iconcdeucher/terraform-aws-vpc
resource "aws_spot_instance_request" "webserver_public" {
  ami           = var.ami
  instance_type = var.instance_type
  spot_price    = var.spot_price
  subnet_id     = var.subnet_public.id

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 Instance Request?

AWS Amazon EC2 Instance 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 Instance Request?

For Terraform, the ggirault/poc-vpc-shared, Angelo512/Terabyte-CIT481-Senior-Project and cdeucher/terraform-aws-vpc source code examples are useful. See the Terraform Example section for further details.