Get-CECostAndUsageWithResource : Hourly timePeriod is not supported for this request #3037
-
Describe the bugRunning this PowerShell query and getting error for I am using the latest version of AWS.Tools.CostExplorer [Version: 4.1.398]
Expected BehaviorI am expecting it to return the cost detail for daily or monthly granularity. Current BehaviorIn all the cases Hourly/Daily/Monthly I am getting the same error as mentioned in the title. Reproduction Stepsrun the code mentioned in the bug description. Possible SolutionNo response Additional Information/ContextNo response AWS .NET SDK and/or Package version usedAWS.Tools.CostExplorer [Version: 4.1.398] Targeted .NET PlatformPowerShell 5.1 Operating System and versionWindows |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 1 reply
-
Ideally this issue should have been opened in https://github.com/aws/aws-tools-for-powershell repository. But looks like CostExplorer CmdLets are auto-generated and these make underlying .NET service API call. So the issue could be narrowed down to making a service API call via .NET SDK. Most likely this is a service API issue where service doesn't support Hourly timePeriod for certain request type. Needs reproduction and investigation. |
Beta Was this translation helpful? Give feedback.
-
Tried to reproduce the issue using the below code: using Amazon.CostExplorer;
using Amazon.CostExplorer.Model;
Amazon.AWSConfigs.LoggingConfig.LogResponses = Amazon.ResponseLoggingOption.Always;
Amazon.AWSConfigs.LoggingConfig.LogTo = Amazon.LoggingOptions.SystemDiagnostics;
Amazon.AWSConfigs.AddTraceListener("Amazon", new System.Diagnostics.ConsoleTraceListener());
var client = new AmazonCostExplorerClient();
var request = new GetCostAndUsageWithResourcesRequest()
{
Granularity = Granularity.DAILY,
Metrics = new List<string>() { "BlendedCost" },
TimePeriod = new DateInterval() { Start = "2023-08-22", End = "2023-07-10" }
};
var response = await client.GetCostAndUsageWithResourcesAsync(request);
Console.WriteLine(response.HttpStatusCode); Got the error:
During debugging, it was indeed confirmed that the {"Granularity":"DAILY","Metrics":["BlendedCost"],"TimePeriod":{"End":"2023-07-10","Start":"2023-08-22"}} The error is returned by the service. Upon closer look, noticed that the user appears to use incorrect After flipping @50ur48h Looks like your Thanks, |
Beta Was this translation helpful? Give feedback.
-
Transferred the issue to shared repo https://github.com/aws/aws-sdk for better management since other SDK(s) might also be impacted. |
Beta Was this translation helpful? Give feedback.
-
P97668847 |
Beta Was this translation helpful? Give feedback.
-
@50ur48h Good afternoon. Just checked with service team. Looks like you are using the API incorrectly. The using Amazon.CostExplorer;
using Amazon.CostExplorer.Model;
Amazon.AWSConfigs.LoggingConfig.LogResponses = Amazon.ResponseLoggingOption.Always;
Amazon.AWSConfigs.LoggingConfig.LogTo = Amazon.LoggingOptions.SystemDiagnostics;
Amazon.AWSConfigs.AddTraceListener("Amazon", new System.Diagnostics.ConsoleTraceListener());
var client = new AmazonCostExplorerClient();
var request = new GetCostAndUsageWithResourcesRequest()
{
Granularity = Granularity.DAILY,
Metrics = new List<string>() { "BlendedCost" },
TimePeriod = new DateInterval() { Start = "2023-08-08", End = "2023-08-22" },
GroupBy = new List<GroupDefinition>() { new GroupDefinition() { Type = "DIMENSION", Key = "RESOURCE_ID" } }
};
var response = await client.GetCostAndUsageWithResourcesAsync(request);
Console.WriteLine(response.HttpStatusCode); Although I now get error Thanks, |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
@50ur48h Good afternoon. Just checked with service team. Looks like you are using the API incorrectly. The
GetCostAndUsageWithResources
mentions thatTimePeriod
range must be within the last14 days
(the start date cannot be earlier than 14 days ago). Take explicit note of the fact that the start date cannot be earlier than 14 days ago. Also, based on testing you would also need to haveRESOURCE_ID
as one of theDIMENSION
in eitherGroupBy
orFilter
clause. So the below .NET SDK code appears to work: