How to get Reservations Utilization from AWS Cost explorer for both virtual machines and RDS at the same time?
I tried following code, but it throws error as we are allowed to pass only 1 service at a time.
final GetReservationUtilizationRequest request = new GetReservationUtilizationRequest()
.withFilter(new Expression().
withAnd(new Expression().
withDimensions(new DimensionValues()
.withKey("SERVICE").withValues("Amazon Elastic Compute Cloud - Compute")), new Expression()
.withDimensions(new DimensionValues()
.withKey("SERVICE").withValues("Amazon Relational Database Service"))))
.withGroupBy(Collections.singletonList(
new GroupDefinition()
.withType("DIMENSION")
.withKey("SUBSCRIPTION_ID")))
.withTimePeriod(new DateInterval()
.withStart(Objects.requireNonNull(startDate).format(ISO_LOCAL_DATE))
.withEnd(Objects.requireNonNull(endDate).format(ISO_LOCAL_DATE)));
This is current Request
Output:
The following dimensions are filtered more than once: Service (Service: AWSCostExplorer; Status Code: 400; Error Code: ValidationException; Request ID: 76e77a0b-ba13-44a1-a8f5-161146b9f8b0; Proxy: null)
Correct way to club services
final GetReservationUtilizationRequest request = new GetReservationUtilizationRequest()
.withFilter(new Expression().
withDimensions(new DimensionValues()
.withKey("SERVICE").withValues("Amazon Elastic Compute Cloud - Compute", "Amazon Relational Database Service")))
.withGroupBy(Collections.singletonList(
new GroupDefinition()
.withType("DIMENSION")
.withKey("SUBSCRIPTION_ID")))
.withTimePeriod(new DateInterval()
.withStart(Objects.requireNonNull(startDate).format(ISO_LOCAL_DATE))
.withEnd(Objects.requireNonNull(endDate).format(ISO_LOCAL_DATE)));