搭配使用 AllocateHosts 與 CLI - AWS SDK 程式碼範例

AWS文件開發套件範例 GitHub 儲存庫中有更多可用的 AWS SDK 範例。

搭配使用 AllocateHosts 與 CLI

下列程式碼範例示範如何使用 AllocateHosts

CLI
AWS CLI

範例 1:配置專用主機

下列 allocate-hosts 範例會在 eu-west-1a 可用區域中配置單一專用主機,您可以在其上啟動 m5.large 執行個體。根據預設,專用主機僅接受目標執行個體啟動,且不支援主機復原。

aws ec2 allocate-hosts \ --instance-type m5.large \ --availability-zone eu-west-1a \ --quantity 1

輸出:

{ "HostIds": [ "h-07879acf49EXAMPLE" ] }

範例 2:配置已啟用自動置放和主機復原的專用主機

下列 allocate-hosts 範例會在啟用自動置放和主機復原的 eu-west-1a 可用區域中配置單一專用主機。

aws ec2 allocate-hosts \ --instance-type m5.large \ --availability-zone eu-west-1a \ --auto-placement on \ --host-recovery on \ --quantity 1

輸出:

{ "HostIds": [ "h-07879acf49EXAMPLE" ] }

範例 3:使用標籤配置專用主機

下列 allocate-hosts 範例會配置單一專用主機,並使用名為 purpose 值為 production 的索引鍵來套用標籤。

aws ec2 allocate-hosts \ --instance-type m5.large \ --availability-zone eu-west-1a \ --quantity 1 \ --tag-specifications 'ResourceType=dedicated-host,Tags={Key=purpose,Value=production}'

輸出:

{ "HostIds": [ "h-07879acf49EXAMPLE" ] }

如需詳細資訊,請參閱《Amazon EC2 使用者指南》中的配置專用主機

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 AllocateHosts

PowerShell
Tools for PowerShell V4

範例 1:此範例會將給定執行個體類型和可用區域的專用主機,配置給您的帳戶

New-EC2Host -AutoPlacement on -AvailabilityZone eu-west-1b -InstanceType m4.xlarge -Quantity 1

輸出:

h-01e23f4cd567890f3
  • 如需 API 詳細資訊,請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》中的 AllocateHosts

Tools for PowerShell V5

範例 1:此範例會將給定執行個體類型和可用區域的專用主機,配置給您的帳戶

New-EC2Host -AutoPlacement on -AvailabilityZone eu-west-1b -InstanceType m4.xlarge -Quantity 1

輸出:

h-01e23f4cd567890f3
  • 如需 API 詳細資訊,請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》中的 AllocateHosts