2

Amazon EC2 定价 api 为每种定价类型提供不同的属性,我如何知道我的 ec2 实例在哪种定价下运行。因为在定价 api 即 json 文件中,亚马逊提供了很少的属性,并且在这些属性中,我只能从实例内部获取 instanceType。如何得到别人?

[
    {
        "TDVRYW6K68T4XJHJ.JRTCKXETXF": {
            "effectiveDate": "2016-01-01T00:00:00Z", 
            "offerTermCode": "JRTCKXETXF", 
            "priceDimensions": {
                "TDVRYW6K68T4XJHJ.JRTCKXETXF.6YS6EN2CT7": {
                    "appliesTo": [], 
                    "beginRange": "0", 
                    "description": "$4.900 per On Demand Linux hs1.8xlarge Instance Hour", 
                    "endRange": "Inf", 
                    "pricePerUnit": {
                        "USD": "4.9000000000"
                    }, 
                    "rateCode": "TDVRYW6K68T4XJHJ.JRTCKXETXF.6YS6EN2CT7", 
                    "unit": "Hrs"
                }
            }, 
            "sku": "TDVRYW6K68T4XJHJ", 
            "termAttributes": {}
        }, 
        "attributes": {
            "clockSpeed": "2 GHz", 
            "currentGeneration": "No", 
            "instanceFamily": "Storage optimized", 
            "instanceType": "hs1.8xlarge", 
            "licenseModel": "No License required", 
            "location": "EU (Ireland)", 
            "locationType": "AWS Region", 
            "memory": "117 GiB", 
            "networkPerformance": "10 Gigabit", 
            "operatingSystem": "Linux", 
            "operation": "RunInstances", 
            "physicalProcessor": "Intel Xeon E5-2650", 
            "preInstalledSw": "NA", 
            "processorArchitecture": "64-bit", 
            "servicecode": "AmazonEC2", 
            "storage": "24 x 2000", 
            "tenancy": "Shared", 
            "usagetype": "EU-BoxUsage:hs1.8xlarge", 
            "vcpu": "17"
        }
    }
]
4

1 回答 1

0

1) 找到您的实例大小和可用区。例如

[ec2-user@ip-10-50-1-171 temp]$ ec2-metadata |grep placement
placement: eu-west-1a
[ec2-user@ip-10-50-1-171 temp]$ ec2-metadata |grep instance-type
instance-type: t2.micro

2) 为 EC2 的定价提取正确的文件,例如目前它是 https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index。 json

3)在这个文件中有“产品”。因此,例如在产品中为 eu-west 找到一个 t2.micro

"SYEPG42MVWFMUBT6" : {
  "sku" : "SYEPG42MVWFMUBT6",
  "productFamily" : "Compute Instance",
  "attributes" : {
    "servicecode" : "AmazonEC2",
    "location" : "EU (Ireland)",
    "locationType" : "AWS Region",
    "instanceType" : "t2.micro",
    "instanceFamily" : "General purpose",
    "vcpu" : "1",
    "physicalProcessor" : "Intel Xeon Family",
    "clockSpeed" : "Up to 3.3 GHz",
    "memory" : "1 GiB",
    "storage" : "EBS only",
    "networkPerformance" : "Low to Moderate",
    "processorArchitecture" : "32-bit or 64-bit",
    "tenancy" : "Shared",
    "operatingSystem" : "SUSE",
    "licenseModel" : "No License required",
    "usagetype" : "EU-BoxUsage:t2.micro",
    "operation" : "RunInstances:000g",
    "preInstalledSw" : "NA",
    "processorFeatures" : "Intel AVX; Intel Turbo"
  }
},

记下此产品的 SKU

4)接下来在json文件中找到“terms”部分。有“按需”和“保留”部分。在“OnDemand”中,感兴趣的产品的 SKU(在上面的示例中为 SYEPG42MVWFMUBT6)被提及一次。在“保留”中有几个条目具有不同的术语

如果您需要以编程方式完成所有这些步骤,则必须使用 shell 脚本和 jq 之类的工具或用于 json 处理的库,例如 python 中包含的库

于 2016-02-09T11:36:40.860 回答