AWS 價格表 使用 的範例 AWS CLI - AWS SDK 程式碼範例

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

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

AWS 價格表 使用 的範例 AWS CLI

下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 來執行動作和實作常見案例 AWS 價格表。

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會示範如何呼叫個別服務函數,但您可以在相關案例中查看內容中的動作。

每個範例都包含完整原始程式碼的連結,您可以在其中找到如何在內容中設定和執行程式碼的指示。

主題

動作

下列程式碼範例示範如何使用 describe-services

AWS CLI

擷取服務中繼資料

此範例會擷取 Amazon EC2 服務程式碼的中繼資料。

命令:

aws pricing describe-services --service-code AmazonEC2 --format-version aws_v1 --max-items 1

輸出:

{ "Services": [ { "ServiceCode": "AmazonEC2", "AttributeNames": [ "volumeType", "maxIopsvolume", "instance", "instanceCapacity10xlarge", "locationType", "instanceFamily", "operatingSystem", "clockSpeed", "LeaseContractLength", "ecu", "networkPerformance", "instanceCapacity8xlarge", "group", "maxThroughputvolume", "gpuMemory", "ebsOptimized", "elasticGpuType", "maxVolumeSize", "gpu", "processorFeatures", "intelAvxAvailable", "instanceCapacity4xlarge", "servicecode", "groupDescription", "processorArchitecture", "physicalCores", "productFamily", "enhancedNetworkingSupported", "intelTurboAvailable", "memory", "dedicatedEbsThroughput", "vcpu", "OfferingClass", "instanceCapacityLarge", "capacitystatus", "termType", "storage", "intelAvx2Available", "storageMedia", "physicalProcessor", "provisioned", "servicename", "PurchaseOption", "instanceCapacity18xlarge", "instanceType", "tenancy", "usagetype", "normalizationSizeFactor", "instanceCapacity2xlarge", "instanceCapacity16xlarge", "maxIopsBurstPerformance", "instanceCapacity12xlarge", "instanceCapacity32xlarge", "instanceCapacityXlarge", "licenseModel", "currentGeneration", "preInstalledSw", "location", "instanceCapacity24xlarge", "instanceCapacity9xlarge", "instanceCapacityMedium", "operation" ] } ], "FormatVersion": "aws_v1" }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DescribeServices

下列程式碼範例示範如何使用 get-attribute-values

AWS CLI

擷取屬性值清單

下列get-attribute-values範例會擷取指定屬性可用的值清單。

aws pricing get-attribute-values \ --service-code AmazonEC2 \ --attribute-name volumeType \ --max-items 2

輸出:

{ "NextToken": "eyJOZXh0VG9rZW4iOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQiOiAyfQ==", "AttributeValues": [ { "Value": "Cold HDD" }, { "Value": "General Purpose" } ] }

下列程式碼範例示範如何使用 get-products

AWS CLI

擷取產品清單

此範例會擷取符合指定條件的產品清單。

命令:

aws pricing get-products --filters file://filters.json --format-version aws_v1 --max-results 1 --service-code AmazonEC2

filters.json:

[ { "Type": "TERM_MATCH", "Field": "ServiceCode", "Value": "AmazonEC2" }, { "Type": "TERM_MATCH", "Field": "volumeType", "Value": "Provisioned IOPS" } ]

輸出:

{ "FormatVersion": "aws_v1", "NextToken": "WGDY7ko8fQXdlaUZVdasFQ==:RVSagyIFn770XQOzdUIcO9BY6ucBG9itXAZGZF/zioUzOsUKh6PCcPWaOyPZRiMePb986TeoKYB9l55fw/CyoMq5ymnGmT1Vj39TljbbAlhcqnVfTmPIilx8Uy5bdDaBYy/e/2Ofw9Edzsykbs8LTBuNbiDQ+BBds5yeI9AQkUepruKk3aEahFPxJ55kx/zk", "PriceList": [ "{\"product\":{\"productFamily\":\"Storage\",\"attributes\":{\"storageMedia\":\"SSD-backed\",\"maxThroughputvolume\":\"320 MB/sec\",\"volumeType\":\"Provisioned IOPS\",\"maxIopsvolume\":\"20000\",\"servicecode\":\"AmazonEC2\",\"usagetype\":\"APS1-EBS:VolumeUsage.piops\",\"locationType\":\"AWS Region\",\"location\":\"Asia Pacific (Singapore)\",\"servicename\":\"Amazon Elastic Compute Cloud\",\"maxVolumeSize\":\"16 TiB\",\"operation\":\"\"},\"sku\":\"3MKHN58N7RDDVGKJ\"},\"serviceCode\":\"AmazonEC2\",\"terms\":{\"OnDemand\":{\"3MKHN58N7RDDVGKJ.JRTCKXETXF\":{\"priceDimensions\":{\"3MKHN58N7RDDVGKJ.JRTCKXETXF.6YS6EN2CT7\":{\"unit\":\"GB-Mo\",\"endRange\":\"Inf\",\"description\":\"$0.138 per GB-month of Provisioned IOPS SSD (io1) provisioned storage - Asia Pacific (Singapore)\",\"appliesTo\":[],\"rateCode\":\"3MKHN58N7RDDVGKJ.JRTCKXETXF.6YS6EN2CT7\",\"beginRange\":\"0\",\"pricePerUnit\":{\"USD\":\"0.1380000000\"}}},\"sku\":\"3MKHN58N7RDDVGKJ\",\"effectiveDate\":\"2018-08-01T00:00:00Z\",\"offerTermCode\":\"JRTCKXETXF\",\"termAttributes\":{}}}},\"version\":\"20180808005701\",\"publicationDate\":\"2018-08-08T00:57:01Z\"}" ] }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 GetProducts