【问题标题】:Query amazon ec2 attributes from inside instance for checking pricing从内部实例查询 amazon ec2 属性以检查定价
【发布时间】:2016-05-18 22:28:12
【问题描述】:

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"
        }
    }
]

【问题讨论】:

  • 能否请您添加更多信息,例如您正在寻找哪些属性来区分定价。据我所知,位置是唯一的变量,其他信息可从实例类型派生。

标签: amazon-web-services amazon-ec2 price


【解决方案1】:

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 附带的库)

【讨论】:

  • 是的,我想以编程方式进行,所以,问题是:- 我们是否能够仅使用 ec2 实例中的这两个详细信息,将从该 json 文件过滤的结果缩小到一个 sku?
  • 使用您选择的编程或脚本语言,加载 json 并使用可用区和实例类型选择“产品”。这会给你一个 SKU。然后使用 SKU 查找相应的“条款”
  • 虽然没有足够的信息 - 此处示例中的 t2.micro 可以是 Amazon Linux、RHEL、SUSE、Windows 等。
  • @thomas 好点。这也是一个古老的答案。有关付费 AMI 的一些信息,请参阅 docs.aws.amazon.com/AWSEC2/latest/UserGuide/paid-amis.html
  • 老实说,我认为答案并没有真正改变。使用定价 API 来获取实例的价格仍然是不可能的(至少即使付出了中等的努力)。 EC2 调用中没有足够的信息来完全过滤定价 API。
猜你喜欢
  • 2015-03-07
  • 2011-04-22
  • 2011-07-08
  • 2012-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多