AWS Pricing API区域名称

时间:2017-01-12 08:21:52

标签: amazon-web-services amazon-ec2

我正在使用AWS Pricing API:

http://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/price-changes.html

问题是它有像

这样的数据
"KV46EU5KJGKB53ZX" : {
  "sku" : "KV46EU5KJGKB53ZX",
  "productFamily" : "Compute Instance",
  "attributes" : {
    "servicecode" : "AmazonEC2",
    "location" : "US East (N. Virginia)",
    "locationType" : "AWS Region",

我不知道如何将locationTypelocation与我用于启动EC2实例的数据相关联(例如在us-east-1中)。

有没有办法知道启动EC2实例的成本?

3 个答案:

答案 0 :(得分:1)

我不知道价格表API提供的结构中是否存在此交叉引用/映射数据,但遗憾的是,EC2 API中的DescribeRegions并未提供此数据。

但是,它可以在一般文档下的Regions and Endpoints页面上找到。从该信息中,您可以构建一个简单的字典或查找表。

答案 1 :(得分:1)

只需自己构建即可。我知道它不会被更新,但是...

注意:我从AWS定价用户界面中提取的此列表中缺少中国

{
    "AWS GovCloud (US-East)": "us-gov-east-1",
    "AWS GovCloud (US-West)": "us-gov-west-1",
    "Africa (Cape Town)": "af-south-1",
    "Asia Pacific (Hong Kong)": "ap-east-1",
    "Asia Pacific (Mumbai)": "ap-south-1",
    "Asia Pacific (Osaka-Local)": "ap-northeast-3",
    "Asia Pacific (Seoul)": "ap-northeast-2",
    "Asia Pacific (Singapore)": "ap-southeast-1",
    "Asia Pacific (Sydney)": "ap-southeast-2",
    "Asia Pacific (Tokyo)": "ap-northeast-1",
    "Canada (Central)": "ca-central-1",
    "EU (Frankfurt)": "eu-central-1",
    "EU (Ireland)": "eu-west-1",
    "EU (London)": "eu-west-2",
    "EU (Milan)": "eu-south-1",
    "EU (Paris)": "eu-west-3",
    "EU (Stockholm)": "eu-north-1",
    "Middle East (Bahrain)": "me-south-1",
    "South America (Sao Paulo)": "sa-east-1",
    "US East (Boston)": "us-east-1-bos-1",
    "US East (Houston)": "us-east-1-iah-1",
    "US East (Miami)": "us-east-1-mia-1",
    "US East (N. Virginia)": "us-east-1",
    "US East (Ohio)": "us-east-2",
    "US East (Verizon) - Atlanta": "us-east-1-wl1-atl1",
    "US East (Verizon) - Boston": "us-east-1-wl1",
    "US East (Verizon) - Dallas": "us-east-1-wl1-dfw1",
    "US East (Verizon) - Miami": "us-east-1-wl1-mia1",
    "US East (Verizon) - New York": "us-east-1-wl1-nyc1",
    "US East (Verizon) - Washington DC": "us-east-1-wl1-was1",
    "US West (Los Angeles)": "us-west-2-lax-1",
    "US West (N. California)": "us-west-1",
    "US West (Oregon)": "us-west-2",
    "US West (Verizon) - Las Vegas": "us-west-2-wl1-las1",
    "US West (Verizon) - San Francisco Bay Area": "us-west-2-wl1",
}

答案 2 :(得分:0)

我建议使用jq来处理大型json文档。例如,对于sku KV46EU5KJGKB53ZX的OnDemand定价:

int solver(int num) //gets an integer
{
    string numString = to_string(num); //convert integer to string so i can manipulate individual digits
    int divisible=0; //will store a count of digits in "num" which can be divided evenly

    for (int x = 1; x <= (end(numString) - begin(numString))/*string length*/; x++)
    {

        if (numString[x-1] == 0 || (end(numString) - begin(numString))-x >=1) //ignore digits which are 0 and or 0s that are last in the array
            ++x;

        if (num % numString[x - 1] == 0) //THIS NEVER EVALUATES TO TRUE. HOW COME???
            divisible++; 

    }
    return divisible;  //number of digits in variable "num" which can be evenly divided
}

给出

curl -s https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json \
 | jq .terms.OnDemand.KV46EU5KJGKB53ZX