

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# Spot 執行個體請求啟動規格範例
<a name="spot-request-examples"></a>

下列範例顯示您可搭配 [request-spot-instances](https://docs.aws.amazon.com/cli/latest/reference/ec2/request-spot-instances.html) 命令使用的啟動組態，以建立 Spot 執行個體請求。如需詳細資訊，請參閱[管理您的 Spot 執行個體](using-spot-instances-request.md)。

**重要**  
我們強烈反對使用 [request-spot-instances](https://docs.aws.amazon.com/cli/latest/reference/ec2/request-spot-instances.html) 命令來請求 Spot 執行個體，因為這是一個沒有計劃投資的舊式 API。如需詳細資訊，請參閱 [使用哪種 Spot 請求方法最好？](spot-best-practices.md#which-spot-request-method-to-use)

**Topics**
+ [範例 1：啟動 競價型執行個體](#spot-launch-specification1)
+ [範例 2：在指定的可用區域中啟動 競價型執行個體](#spot-launch-specification2)
+ [範例 3：在指定的子網中啟動 競價型執行個體](#spot-launch-specification3)
+ [範例 4：啟動專用 Spot 執行個體](#spot-launch-specification4)

## 範例 1：啟動 競價型執行個體
<a name="spot-launch-specification1"></a>

下列範例不包括可用區域或子網。Amazon EC2 為您選取可用區域。Amazon EC2 會在所選可用區域的預設子網中啟動執行個體。

```
{
  "ImageId": "ami-0abcdef1234567890",
  "KeyName": "my-key-pair",
  "SecurityGroupIds": [ "sg-1a2b3c4d5e6f7g8h9" ],
  "InstanceType": "m5.medium",
  "IamInstanceProfile": {
      "Arn": "arn:aws:iam::123456789012:instance-profile/my-iam-role"
  }
}
```

## 範例 2：在指定的可用區域中啟動 競價型執行個體
<a name="spot-launch-specification2"></a>

下列範例包括可用區域。Amazon EC2 會在指定可用區域的預設子網中啟動執行個體。

```
{
  "ImageId": "ami-0abcdef1234567890",
  "KeyName": "my-key-pair",
  "SecurityGroupIds": [ "sg-1a2b3c4d5e6f7g8h9" ],
  "InstanceType": "m5.medium",
  "Placement": {
    "AvailabilityZone": "us-west-2a"
  },
  "IamInstanceProfile": {
      "Arn": "arn:aws:iam::123456789012:instance-profile/my-iam-role"
  }
}
```

## 範例 3：在指定的子網中啟動 競價型執行個體
<a name="spot-launch-specification3"></a>

下列範例包含子網。Amazon EC2 會在指定子網中啟動執行個體。如果 VPC 為非預設 VPC，則執行個體預設不會接收公有 IPv4 地址。

```
{
  "ImageId": "ami-0abcdef1234567890",
  "SecurityGroupIds": [ "sg-1a2b3c4d5e6f7g8h9" ],
  "InstanceType": "m5.medium",
  "SubnetId": "subnet-1a2b3c4d",
  "IamInstanceProfile": {
      "Arn": "arn:aws:iam::123456789012:instance-profile/my-iam-role"
  }
}
```

若要指派公有 IPv4 位址給非預設 VPC 中的執行個體，請依下列範例所示來指定 `AssociatePublicIpAddress` 欄位。指定網路介面時，您必須填入網路介面的子網 ID 和安全群組 ID，而非使用前例程式碼區塊所示的 `SubnetId` 和 `SecurityGroupIds` 欄位。

```
{
  "ImageId": "ami-0abcdef1234567890",
  "KeyName": "my-key-pair",
  "InstanceType": "m5.medium",
  "NetworkInterfaces": [
    {
      "DeviceIndex": 0,
      "SubnetId": "subnet-1a2b3c4d5e6f7g8h9",
      "Groups": [ "sg-1a2b3c4d5e6f7g8h9" ],
      "AssociatePublicIpAddress": true
    }
  ],
  "IamInstanceProfile": {
      "Arn": "arn:aws:iam::123456789012:instance-profile/my-iam-role"
  }
}
```

## 範例 4：啟動專用 Spot 執行個體
<a name="spot-launch-specification4"></a>

下列範例請求具有`dedicated`租用的 Spot 執行個體。專用 Spot 執行個體必須在 VPC 中啟動。

```
{
  "ImageId": "ami-0abcdef1234567890",
  "KeyName": "my-key-pair",
  "SecurityGroupIds": [ "sg-1a2b3c4d5e6f7g8h9" ],
  "InstanceType": "c5.8xlarge",
  "SubnetId": "subnet-1a2b3c4d5e6f7g8h9",
  "Placement": {
    "Tenancy": "dedicated"
  }
}
```