[{"data":1,"prerenderedAt":88},["ShallowReactive",2],{"/2025/12/15-amazon-cloudwatch-getmetricdata-api-samplecount-returns-0":3},{"id":4,"title":5,"body":6,"date":79,"description":76,"extension":80,"meta":81,"navigation":82,"path":83,"robots":84,"seo":85,"stem":86,"__hash__":87},"posts/2025/12/15 Amazon-CloudWatch-GetMetricData-API-SampleCount-returns-0.md","15 Amazon CloudWatch GetMetricData API SampleCount Returns 0",{"type":7,"value":8,"toc":75},"minimark",[9,18,25,28,31,33,36,49,51,54,56,59,61,70,72],[10,11,13],"post-title",{":date":12},"date",[14,15,17],"h1",{"id":16},"amazon-cloudwatch-getmetricdata-api-samplecount-returns-0","Amazon CloudWatch GetMetricData API SampleCount Returns 0",[19,20,21],"notes",{},[22,23,24],"p",{},"This is a repost from my old blog. First posted in 8/17/2020.",[26,27],"br",{},[22,29,30],{},"One of our code is to keep track on how many data points are there for each CloudWatch metric. So, I usually use the GetMetricData API with statistic set to SampleCount. But since we only care about the total, I don't use short period (high resolution). Partly, it is to reduce the amount of data returned. However, in one case, it returns 0 for a particular month.",[26,32],{},[22,34,35],{},"According to the following documentation, period has to be a multiply of 60:",[22,37,38],{},[39,40,43],"span",{"className":41},[42],"text-blue-600",[44,45,46],"a",{"href":46,"rel":47},"https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDataQuery.html",[48],"nofollow",[26,50],{},[22,52,53],{},"No problem, since my start time and end time is exactly one month apart, I will just set the period to the number of seconds between start time and end time to get highest number of period. It works for some months, it returns 0 in this particular case.",[26,55],{},[22,57,58],{},"Strange until I found out in a different documentation that there's a max period of 86,400 seconds (one day).",[26,60],{},[22,62,63],{},[39,64,66],{"className":65},[42],[44,67,68],{"href":68,"rel":69},"https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Statistic",[48],[26,71],{},[22,73,74],{},"I change my period to 86400 and it no longer returns 0.",{"title":76,"searchDepth":77,"depth":77,"links":78},"",2,[],"2025-12-15T00:00:00.000Z","md",{},true,"/2025/12/15-amazon-cloudwatch-getmetricdata-api-samplecount-returns-0",null,{"title":5,"description":76},"2025/12/15 Amazon-CloudWatch-GetMetricData-API-SampleCount-returns-0","BS9xCy0cr1A6xCKsxDjGAKZRjTaEWHqarCA_3nU0GlI",1785167452184]