I've created different AWS resources across EC2, Storage, Load Balancer, Networks etc. I've tagged each resource with GroupName
as a key and value which is different for each group e.g. group1
, group2
, etc.
Now, I want to get cost of each group. I've written following code
GroupDefinition groupDefinition =
new GroupDefinition().withType(GroupDefinitionType.TAG).withKey("Cluster");
GetCostAndUsageRequest costAndUsageRequest
= new GetCostAndUsageRequest()
.withGroupBy(groupDefinition)
.withGranularity("MONTHLY")
.withMetrics("UnblendedCost");
GetCostAndUsageResult costAndUsage =
awsCostExplorer.getCostAndUsage(costAndUsageRequest);
Now, I expect the costAndUsage
has groups based on each tag. But it's always giving me the total bill. I can give any random value to withKey
but the result is always the same.
Maven dependency:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.453</version>
</dependency>
This is the response I'm getting (first resultByTime
for brevity)
{
"timePeriod":{
"start":"2018-11-01",
"end":"2018-12-01"
},
"total":{
},
"groups":[
{
"keys":[
"Cluster$"
],
"metrics":{
"UnblendedCost":{
"amount":"26712.9751185906",
"unit":"USD"
}
}
}
],
"estimated":false
}
What I would like to have is
Cluster1 -> 1500 USD
Cluster2 -> 1000 USD
Assuming I have a bunch of resources tagged with key Cluster
and values Cluster1
and Cluster2
.
There's no grouping by each actual tag value in the response. What am I missing here?