搭DescribeSpotPriceHistory配 AWS SDK或使用 CLI - AWS SDK 程式碼範例

AWS 文檔 AWS SDK示例 GitHub 回購中有更多SDK示例

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

DescribeSpotPriceHistory配 AWS SDK或使用 CLI

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

CLI
AWS CLI

描述現貨價格歷史

此範例指令會傳回一月特定日期 m1.xlarge 執行個體的現貨價格歷史記錄。

命令:

aws ec2 describe-spot-price-history --instance-types m1.xlarge --start-time 2014-01-06T07:08:09 --end-time 2014-01-06T08:09:10

輸出:

{ "SpotPriceHistory": [ { "Timestamp": "2014-01-06T07:10:55.000Z", "ProductDescription": "SUSE Linux", "InstanceType": "m1.xlarge", "SpotPrice": "0.087000", "AvailabilityZone": "us-west-1b" }, { "Timestamp": "2014-01-06T07:10:55.000Z", "ProductDescription": "SUSE Linux", "InstanceType": "m1.xlarge", "SpotPrice": "0.087000", "AvailabilityZone": "us-west-1c" }, { "Timestamp": "2014-01-06T05:42:36.000Z", "ProductDescription": "SUSE Linux (Amazon VPC)", "InstanceType": "m1.xlarge", "SpotPrice": "0.087000", "AvailabilityZone": "us-west-1a" }, ... }

說明 LinuxUNIX/Amazon 的現貨價格歷史記錄 VPC

此範例指令會傳回一月特定日期 m1.xlarge、Linux/ UNIX Amazon VPC 執行個體的現貨價格歷史記錄。

命令:

aws ec2 describe-spot-price-history --instance-types m1.xlarge --product-description "Linux/UNIX (Amazon VPC)" --start-time 2014-01-06T07:08:09 --end-time 2014-01-06T08:09:10

輸出:

{ "SpotPriceHistory": [ { "Timestamp": "2014-01-06T04:32:53.000Z", "ProductDescription": "Linux/UNIX (Amazon VPC)", "InstanceType": "m1.xlarge", "SpotPrice": "0.080000", "AvailabilityZone": "us-west-1a" }, { "Timestamp": "2014-01-05T11:28:26.000Z", "ProductDescription": "Linux/UNIX (Amazon VPC)", "InstanceType": "m1.xlarge", "SpotPrice": "0.080000", "AvailabilityZone": "us-west-1c" } ] }
PowerShell
用於的工具 PowerShell

範例 1:此範例會取得指定執行個體類型和可用區域的 Spot 價格歷史記錄中的最後 10 個項目。請注意,為-AvailabilityZone 參數指定的值必須對提供給指令程式之-Region 參數的區域值有效 (未顯示在範例中),或在命令介面中設定為預設值。此範例指令假設環境中已設定「us-west-2 的預設區域。

Get-EC2SpotPriceHistory -InstanceType c3.large -AvailabilityZone us-west-2a -MaxResult 10

輸出:

AvailabilityZone : us-west-2a InstanceType : c3.large Price : 0.017300 ProductDescription : Linux/UNIX (Amazon VPC) Timestamp : 12/25/2015 7:39:49 AM AvailabilityZone : us-west-2a InstanceType : c3.large Price : 0.017200 ProductDescription : Linux/UNIX (Amazon VPC) Timestamp : 12/25/2015 7:38:29 AM AvailabilityZone : us-west-2a InstanceType : c3.large Price : 0.017300 ProductDescription : Linux/UNIX (Amazon VPC) Timestamp : 12/25/2015 6:57:13 AM ...