【问题标题】:how to get the estimated cost of an ec2-instance of type m4.large with ebs storage of 500gb?如何获得 ebs 存储为 500gb 的 m4.large 类型的 ec2 实例的估计成本?
【发布时间】:2019-03-27 16:03:24
【问题描述】:

如何通过 java sdk 获得大约 500gb 的 ebs 存储的 tpe m4.large 的 ec2 实例的估计成本? aws为此提供了任何特定的sdk吗?我试图查看许多 aws api,但我没有找到任何链接,我发现的链接很难理解,并且在实例类型和成本方面从这里获取值,这里是链接: https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonS3/current/us-east-1/index.json

是否有任何 java api 或 sdk 可用于获取实例的估计成本?

【问题讨论】:

    标签: amazon-web-services amazon-ec2 aws-sdk aws-java-sdk


    【解决方案1】:

    您可以使用 AWS 成本管理 API,

    Cost Explorer API 允许您以编程方式查询您的成本和使用数据。您可以查询汇总数据,例如每月总费用或每日总使用量。您还可以查询粒度数据,例如生产环境中 Amazon DynamoDB 数据库表的每日写入操作数。

    通过GetCostAndUsage,您可以获得预估成本。有关更多信息,请阅读 AWS 网站上的以下文档:

    https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/API_GetCostAndUsage.html

    https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/Welcome.html

    有样品要求:

    POST / HTTP/1.1
    Host: ce.us-east-1.amazonaws.com
    x-amz-Date: <Date>
    Authorization: AWS4-HMAC-SHA256 Credential=<Credential>, SignedHeaders=contenttype;date;host;user-agent;x-amz-date;x-amz-target;x-amzn-requestid,Signature=<Signature>
    User-Agent: <UserAgentString>
    Content-Type: application/x-amz-json-1.1
    Content-Length: <PayloadSizeBytes>
    Connection: Keep-Alive
    X-Amz-Target: AWSInsightsIndexService.GetCostAndUsage
    {
      "TimePeriod": {
        "Start":"2017-09-01",
        "End": "2017-10-01"
      },
      "Granularity": "MONTHLY",
      "Filter": {      
        "Dimensions": {
          "Key": "SERVICE",
          "Values": [
            "Amazon Simple Storage Service"
          ]
        }
      },
      "GroupBy":[
        {
          "Type":"DIMENSION",
          "Key":"SERVICE"
        },
        {
          "Type":"TAG",
          "Key":"Environment"
        }
      ],
       "Metrics":["BlendedCost", "UnblendedCost", "UsageQuantity"]
    }
    

    然后回应:

    HTTP/1.1 200 OK
    x-amzn-RequestId: <RequestId>
    Content-Type: application/x-amz-json-1.1
    Content-Length: <PayloadSizeBytes>
    Date: <Date>
    {
      "GroupDefinitions": [
        {
          "Key": "SERVICE",
          "Type": "DIMENSION"
        },
        {
          "Key": "Environment",
          "Type": "TAG"
        }
      ],
      "ResultsByTime": [
        {
          "Estimated": false,
          "Groups": [
            {
              "Keys": [
                "Amazon Simple Storage Service",
                "Environment$Prod"
              ],
              "Metrics": {
                "BlendedCost": {
                  "Amount": "39.1603300457",
                  "Unit": "USD"
                },
                "UnblendedCost": {
                  "Amount": "39.1603300457",
                  "Unit": "USD"
                },
                "UsageQuantity": {
                  "Amount": "173842.5440074444",
                  "Unit": "N/A"
                }
              }
            },
            {
              "Keys": [
                "Amazon Simple Storage Service",
                "Environment$Test"
              ],
              "Metrics": {
                "BlendedCost": {
                  "Amount": "0.1337464807",
                  "Unit": "USD"
                },
                "UnblendedCost": {
                 "Amount": "0.1337464807",
                  "Unit": "USD"
                },
                "UsageQuantity": {
                  "Amount": "15992.0786663399",
                  "Unit": "N/A"
                }
              }
            }
          ],
          "TimePeriod": {
            "End": "2017-10-01",
            "Start": "2017-09-01"
          },
          "Total": {}
        }
      ]
    }
    

    对于 Java SDK,请查看此页面:

    https://docs.aws.amazon.com/goto/SdkForJava/ce-2017-10-25/GetCostAndUsage

    此外,AWS 价目表服务对于您的账户中还没有的资源很有帮助,例如,如果您想创建一个 AWS 计算器。

    GetProducts API 为您提供完整的价格信息,您可以根据这些信息自行计算。

    样品请求 GerProducts:

    POST / HTTP/1.1
    Host: api.pricing.<region>.<domain>
    x-amz-Date: <Date>
    Authorization: AWS4-HMAC-SHA256 Credential=<Credential>, SignedHeaders=contenttype;date;host;user-agent;x-amz-date;x-amz-target;x-amzn-requestid,Signature=<Signature>
    User-Agent: <UserAgentString>
    Content-Type: application/x-amz-json-1.1
    Content-Length: <PayloadSizeBytes>
    Connection: Keep-Alive
    X-Amz-Target: AWSPriceListService.GetProducts
    {
        "Filters": [
            {
                "Type": "TERM_MATCH",
                "Field": "ServiceCode",
                "Value": "AmazonEC2"
            },
            {
                "Type": "TERM_MATCH",
                "Field": "volumeType",
                "Value": "Provisioned IOPS"
            }
        ],
        "FormatVersion": "aws_v1",
        "NextToken": null,
        "MaxResults": 1
    }
    

    和回应:

    HTTP/1.1 200 OK
    x-amzn-RequestId: <RequestId>
    Content-Type: application/x-amz-json-1.1
    Content-Length: <PayloadSizeBytes>
    Date: <Date>
    {
        "FormatVersion": "aws_v1",
        "NextToken": "57r3UcqRjDujbzWfHF7Ciw==:ywSmZsD3mtpQmQLQ5XfOsIMkYybSj+vAT+kGmwMFq+K9DGmIoJkz7lunVeamiOPgthdWSO2a7YKojCO+zY4dJmuNl2QvbNhXs+AJ2Ufn7xGmJncNI2TsEuAsVCUfTAvAQNcwwamtk6XuZ4YdNnooV62FjkV3ZAn40d9+wAxV7+FImvhUHi/+f8afgZdGh2zPUlH8jlV9uUtj0oHp8+DhPUuHXh+WBII1E/aoKpPSm3c=",
        "PriceList": [
            "{\"product\":{\"productFamily\":\"Storage\",\"attributes\":{\"storageMedia\":\"SSD-backed\",\"maxThroughputvolume\":\"320 MB/sec\",\"volumeType\":\"Provisioned IOPS\",\"maxIopsvolume\":\"20000\",\"servicecode\":\"AmazonEC2\",\"usagetype\":\"CAN1-EBS:VolumeUsage.piops\",\"locationType\":\"AWS Region\",\"location\":\"Canada (Central)\",\"servicename\":\"Amazon Elastic Compute Cloud\",\"maxVolumeSize\":\"16 TiB\",\"operation\":\"\"},\"sku\":\"WQGC34PB2AWS8R4U\"},\"serviceCode\":\"AmazonEC2\",\"terms\":{\"OnDemand\":{\"WQGC34PB2AWS8R4U.JRTCKXETXF\":{\"priceDimensions\":{\"WQGC34PB2AWS8R4U.JRTCKXETXF.6YS6EN2CT7\":{\"unit\":\"GB-Mo\",\"endRange\":\"Inf\",\"description\":\"$0.138 per GB-month of Provisioned IOPS SSD (io1)  provisioned storage - Canada (Central)\",\"appliesTo\":[],\"rateCode\":\"WQGC34PB2AWS8R4U.JRTCKXETXF.6YS6EN2CT7\",\"beginRange\":\"0\",\"pricePerUnit\":{\"USD\":\"0.1380000000\"}}},\"sku\":\"WQGC34PB2AWS8R4U\",\"effectiveDate\":\"2017-08-01T00:00:00Z\",\"offerTermCode\":\"JRTCKXETXF\",\"termAttributes\":{}}}},\"version\":\"20170901182201\",\"publicationDate\":\"2017-09-01T18:22:01Z\"}"
        ]
    }
    

    有关更多信息,请阅读以下文档:

    https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/API_pricing_GetProducts.html

    最后,您可以从 AWS 成本计算器中了解:

    https://calculator.s3.amazonaws.com/index.html

    【讨论】:

    • 这些成本管理 api 可以根据我的实例模式预测成本,但我想在直接通过其 api 创建任何类型的任何实例和任何存储之前知道每小时的估计成本
    猜你喜欢
    • 1970-01-01
    • 2021-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-24
    • 2020-10-02
    • 2022-01-05
    • 1970-01-01
    相关资源
    最近更新 更多