I'm studying AWS api to retrieve requisite information about my EC2 instances.
我正在研究AWS api以检索有关我的EC2实例的必要信息。
So, I'm on AWS Cost Explorer Service.
所以,我在AWS Cost Explorer服务上。
It has function 'GetCostAndUsage' that, for example, sends information below. (this is an example from official AWS document)
它具有“GetCostAndUsage”功能,例如,它可以发送以下信息。 (这是官方AWS文档中的一个示例)
{
"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"]
}
and retrieve information below. (this is an example from official AWS document)
并检索以下信息。 (这是官方AWS文档中的一个示例)
{
"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": {}
}
]
}
The retrieved data in key 'Metrics' I guess, it is total cost. not each. So, How can I get each usage and cost for each EC2 instance??
我猜测关键'度量标准'中检索到的数据,这是总成本。不是每一个。那么,我如何获得每个EC2实例的每个使用和成本?
1 个解决方案
#1
0
It's going to be difficult to associate an exact cost with each instance - simple example, you have 2 instances of the same size - one reserved and one on-demand - you run both for 1/2 the month and then turn off one of them for the second 1/2 of the month.
将确切的成本与每个实例相关联是很困难的 - 简单的例子,你有2个相同大小的实例 - 一个保留,一个按需 - 你每月运行1/2,然后关闭其中一个这个月的第二个半月。
You will pay for a reserved instance for the entire month and an on-demand instance for 1/2 the month - but which instance was reserved and which was on-demand? You can't tell; the concept of a reserved instance is just a billing concept, and is not associated with a particular instance.
您将支付整个月的预留实例和每月1/2的按需实例 - 但是哪个实例是保留的并且是按需的?你不能说;保留实例的概念只是一种计费概念,并不与特定实例相关联。
You might be able to approximate what you are looking for - but there are limitations.
您可能能够估算出您正在寻找的东西 - 但也有局限性。
#1
0
It's going to be difficult to associate an exact cost with each instance - simple example, you have 2 instances of the same size - one reserved and one on-demand - you run both for 1/2 the month and then turn off one of them for the second 1/2 of the month.
将确切的成本与每个实例相关联是很困难的 - 简单的例子,你有2个相同大小的实例 - 一个保留,一个按需 - 你每月运行1/2,然后关闭其中一个这个月的第二个半月。
You will pay for a reserved instance for the entire month and an on-demand instance for 1/2 the month - but which instance was reserved and which was on-demand? You can't tell; the concept of a reserved instance is just a billing concept, and is not associated with a particular instance.
您将支付整个月的预留实例和每月1/2的按需实例 - 但是哪个实例是保留的并且是按需的?你不能说;保留实例的概念只是一种计费概念,并不与特定实例相关联。
You might be able to approximate what you are looking for - but there are limitations.
您可能能够估算出您正在寻找的东西 - 但也有局限性。