我正在嘗試在 boto3 中使用 CostExplorer Client 獲取成本。但我找不到用作維度過濾器的值。檔案說我們可以從 GetDimensionValues 中提取這些值,但是如何使用 GetDimensionValues。

response = client.get_cost_and_usage(
TimePeriod={
'Start': str(start_time).split()[0],
'End': str(end_time).split()[0]
},
Granularity='DAILY',
Filter = {
'Dimensions': {
'Key':'USAGE_TYPE',
'Values': [
'DataTransfer-In-Bytes'
]
}
},
Metrics=[
'NetUnblendedCost',
],
GroupBy=[
{
'Type': 'DIMENSION',
'Key': 'SERVICE'
},
]
)
uj5u.com熱心網友回復:
GetDimensionValues 的 boto3參考有很多關于如何使用該呼叫的詳細資訊。下面是一些示例代碼,您可以使用它來列印可能的尺寸值:
response = client.get_dimension_values(
TimePeriod={
'Start': '2022-01-01',
'End': '2022-06-01'
},
Dimension='USAGE_TYPE',
Context='COST_AND_USAGE',
)
for dimension_value in response["DimensionValues"]:
print(dimension_value["Value"])
輸出:
APN1-Catalog-Request
APN1-DataTransfer-Out-Bytes
APN1-Requests-Tier1
APN2-Catalog-Request
APN2-DataTransfer-Out-Bytes
APN2-Requests-Tier1
APS1-Catalog-Request
APS1-DataTransfer-Out-Bytes
.....
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/506411.html
