-
When I try to use more than one USAGE_TYPE_GROUP in the GetUsageForecastRequest API, the following error occurs. Error occurred: Unable to identify the usage unit. Provide USAGE_TYPE/USAGE_TYPE_GROUP filter selections that contain matching units (e.g. hours). (Service: AWSCostExplorer; Status Code: 400; Error Code: UnresolvableUsageUnitException; Request ID: 33248fb8-986e-4358-af0c-49adef64b2da; Proxy: null) My code : public void foreCastTest(String billingAccount) throws IOException {
AWSCostExplorer costExplorer = AWSCostExplorerClientBuilder.standard()
.withCredentials(AWSCredentialsUtil.getCreds(billingAccount))
.build();
GetUsageForecastRequest request = new GetUsageForecastRequest()
.withTimePeriod(new DateInterval().withStart("2023-05-03")
.withEnd("2023-09-01"))
.withGranularity(Granularity.DAILY)
.withMetric(Metric.USAGE_QUANTITY)
.withFilter(new Expression()
.withDimensions(new DimensionValues().withKey(Dimension.USAGE_TYPE_GROUP)
.withValues("EC2: Running Hours", "S3: Storage - Standard")));
try {
GetUsageForecastResult result = costExplorer.getUsageForecast(request);
System.out.println("Usage Forecast: " + result.getForecastResultsByTime());
} catch (Exception e) {
System.err.println("Error occurred: " + e.getMessage());
}
} I'm using aws-java-sdk 1.11.807, and my code looks like this. In addition, the official documentation for GetUsageForecast (https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/API_GetUsageForecast.html) says that the Filter option is not required. However, when I test it on my local PC (version 1.11.807), the following error occurs. Error occurred: Unable to identify the usage unit. Provide USAGE_TYPE/USAGE_TYPE_GROUP filter selections that contain matching units (e.g. hours). (Service: AWSCostExplorer; Status Code: 400; Error Code: UnresolvableUsageUnitException; Request ID: 33248fb8-986e-4358-af0c-49adef64b2da; Proxy: null) Is this issue caused by the difference between the sdk version on my local PC and the official AWS documentation description? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hello @kakjzi, Thank you for submitting your question. Can you try removing the spaces adjacent to the hyphen for the filter value "S3: Storage - Standard"? The hyphenated spaces seems to be an issue when having multiple USAGE_TYPE_GROUP values. I am checking with the Cost Explorer service team for their further investigation on this issue. Also, I have asked the team regarding the documentation that states Filter isn't a required parameter but then we encounter a similar exception when it isn't passed. Regards, |
Beta Was this translation helpful? Give feedback.
-
@bhoradc I did what you suggested and it works fine. Thanks.👍 And let me know if you get an answer to the "similar exception thrown when Filter is not a required parameter but is not passed" question |
Beta Was this translation helpful? Give feedback.
-
@bhoradc Hi, I was wondering if anyone had an answer to my question about a similar exception being thrown if Filter is not a required parameter but is not passed? |
Beta Was this translation helpful? Give feedback.
Hello @kakjzi,
Thank you for submitting your question.
Can you try removing the spaces adjacent to the hyphen for the filter value "S3: Storage - Standard"?
.withValues("EC2: Running Hours", "S3: Storage-Standard")
The hyphenated spaces seems to be an issue when having multiple USAGE_TYPE_GROUP values.
I am checking with the Cost Explorer service team for their further investigation on this issue. Also, I have asked the team regarding the documentation that states Filter isn't a required parameter but then we encounter a similar exception when it isn't passed.
Regards,
Chaitanya