
Trying Out the 30-Day Range Queries Supported by PromQL in Amazon CloudWatch
This page has been translated by machine translation. View original
Introduction
On November 20, 2026, Amazon CloudWatch was updated to extend the PromQL query range for OpenTelemetry metrics from 7 days to 30 days.
In this article, I ran queries through the API to confirm the extended query range. I also tried week-over-week comparisons, which the extended query range makes possible, and expressions for ALB availability over an SLO period and remaining error budget.
Test environment
- Region: Tokyo (ap-northeast-1)
- curl: 8.18.0
- Credentials: temporary credentials with a session token, set in environment variables
- Target metrics: RequestCount and HTTPCode_ELB_5XX_Count of the ALBs in the account (metrics that ALB outputs to CloudWatch)
- Aggregation: sum over all series selected by metric name
- Prerequisite: an account with OTel enrichment enabled (so that ALB metrics can be referenced from PromQL)
Calling the query API
I saved a script that calls /api/v1/query and /api/v1/query_range with curl's SigV4 signing as promql.sh, and made it executable. All the following queries were run with this script. With -G, the --data-urlencode values go into the GET URL; without it, they are sent in the POST body.
#!/usr/bin/env bash
# Usage: promql.sh <region> <query|query_range> <additional arguments to pass to curl...>
# Credentials are read from the environment variables AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY / AWS_SESSION_TOKEN (they are not passed as script arguments)
set -euo pipefail
region="$1"; api="$2"; shift 2
curl -sS --fail-with-body --aws-sigv4 "aws:amz:${region}:monitoring" \
--user "${AWS_ACCESS_KEY_ID}:${AWS_SECRET_ACCESS_KEY}" \
-H "x-amz-security-token: ${AWS_SESSION_TOKEN}" \
"https://monitoring.${region}.amazonaws.com/api/v1/${api}" "$@"
Upper limit of the query range
Width between start and end
A 30-day-wide query_range went through in a single request.
./promql.sh ap-northeast-1 query_range -G \
--data-urlencode 'query=sum({"RequestCount"})' \
--data-urlencode start=1792850430 \
--data-urlencode end=1795442430 \
--data-urlencode step=1h \
| jq -c '{status, resultType:.data.resultType, series:(.data.result|length), points:(.data.result[0].values|length), first:.data.result[0].values[0][0], last:.data.result[0].values[-1][0], warnings}'
{"status":"success","resultType":"matrix","series":1,"points":721,"first":1792850400.0,"last":1795442400.0,"warnings":null}
When I widened the range, the results were as follows.
| Width between start and end | Result |
|---|---|
| 30 days | Success (721 points) |
| 31 days | Success (745 points) |
| 31 days + 1 second | 400 |
The 400 response shows 2678400000ms (31 days) as the upper limit.
Length of the range selector
The range selector can be specified up to 24 hours.
| range selector | Result |
|---|---|
[24h] |
Success |
[25h] |
400 |
[30d] |
400 |
The 400 response shows 86400000ms (24 hours) as the upper limit. [30d] returned 400 for both instant queries and query_range. A subquery (sum_over_time(sum({"RequestCount"})[30d:1d])) also returned 400. To aggregate 30 days in a single expression, line up [24h] windows with offset.
Width of the whole expression
Even when the width between start and end is 30 days, an expression that includes offset can return 400. For expressions using [24h] and offset, the 31-day limit applied to the sum of the width between start and end and the width of the expression's reference period (the length from the oldest time to the newest time that the expression reads). The width of the reference period includes the length of the range selector and the difference between the maximum and minimum offsets in the expression.
For a week-over-week comparison that divides the [24h] daily total by the same expression with offset 7d, the width of the reference period is 8 days. With a 30-day width between start and end it returns 400, and with a 23-day width it fits within 31 days and goes through. An expression with only [24h] at offset 30d has a reference period width of 1 day, so it went through even with a 30-day width. The 30-day total expression described later lines up [24h] from offset 0d to 29d, so its reference period width is 30 days, which fits within the limit.
Queries that use 30 days of data
Week-over-week comparison
I set the width between start and end to 23 days and step to 1 day. Together with the 8-day reference period width, that makes 31 days.
./promql.sh ap-northeast-1 query_range \
--data-urlencode 'query=sum(sum_over_time({"RequestCount"}[24h])) / sum(sum_over_time({"RequestCount"}[24h] offset 7d))' \
--data-urlencode start=1793455200 \
--data-urlencode end=1795442400 \
--data-urlencode step=1d \
| jq -c '{status, points:(.data.result[0].values|length), first3:.data.result[0].values[0:3], last3:.data.result[0].values[-3:]}'
{"status":"success","points":24,"first3":[[1793404800.0,"1.1660977622415951"],[1793491200.0,"1.3497014383324466"],[1793577600.0,"1.0342840556945168"]],"last3":[[1795219200.0,"1.007959577451103"],[1795305600.0,"0.8632162084297997"],[1795392000.0,"0.8168182053724823"]]}
The timestamps of the points aligned to 0:00 UTC, and the first point was at a time earlier than start. Each point is the 24-hour total up to that time divided by the total of the same 24 hours 7 days earlier.
30-day total
The 30-day total is written as a single expression that adds up 30 [24h] windows lined up with offset. Since the expression is long, I saved a generator script as gen-30d-sum.sh and made it executable.
#!/usr/bin/env bash
# Usage: gen-30d-sum.sh <metric name> [days=30] [base offset days=0]
# Outputs a single PromQL expression with [24h] windows lined up by offset for the given number of days (because the upper limit of the range selector is 24 hours).
# If 30 is passed as the base offset days, the expression covers "30 days counted from 30 days ago".
set -euo pipefail
m="$1"; days="${2:-30}"; base="${3:-0}"; out=""
for ((k=0; k<days; k++)); do
o=$((base+k))
if [ "$o" -eq 0 ]; then t="sum(sum_over_time({\"$m\"}[24h]))"; else t="sum(sum_over_time({\"$m\"}[24h] offset ${o}d))"; fi
out+="${out:+ + }(${t} or vector(0))"
done
printf '%s' "$out"
With the metric name RequestCount, the following expression is generated (the terms from offset 2d to 28d are omitted). The or vector(0) at the end of each term makes the term's value 0 when there is no data for that day.
(sum(sum_over_time({"RequestCount"}[24h])) or vector(0)) + (sum(sum_over_time({"RequestCount"}[24h] offset 1d)) or vector(0)) + … + (sum(sum_over_time({"RequestCount"}[24h] offset 29d)) or vector(0))
The 30-term expression is sent via POST without -G.
I aligned the evaluation time to the top of the hour, 1795442400 (2026-11-23T14:00:00Z), and obtained the 30-day totals of RequestCount and HTTPCode_ELB_5XX_Count.
./promql.sh ap-northeast-1 query \
--data-urlencode "query=$(./gen-30d-sum.sh RequestCount)" \
--data-urlencode time=1795442400
{"status":"success","data":{"resultType":"vector","result":[{"metric":{},"value":[1795442400.0,"8734683"]}]}}
./promql.sh ap-northeast-1 query \
--data-urlencode "query=$(./gen-30d-sum.sh HTTPCode_ELB_5XX_Count)" \
--data-urlencode time=1795442400
{"status":"success","data":{"resultType":"vector","result":[{"metric":{},"value":[1795442400.0,"8274"]}]}}
Availability and remaining error budget
Taking HTTPCode_ELB_5XX_Count as the number of failures and RequestCount as the total number of requests, I put the 30-day total expression for each into a bash variable. From these two variables, I calculated availability and remaining error budget, each with a single query.
errors=$(./gen-30d-sum.sh HTTPCode_ELB_5XX_Count)
total=$(./gen-30d-sum.sh RequestCount)
Here is the availability expression.
./promql.sh ap-northeast-1 query \
--data-urlencode "query=1 - (${errors}) / (${total})" \
--data-urlencode time=1795442400
{"status":"success","data":{"resultType":"vector","result":[{"metric":{},"value":[1795442400.0,"0.9990527418110079"]}]}}
Here is the remaining error budget expression, assuming an SLO of 99.9% successful responses.
./promql.sh ap-northeast-1 query \
--data-urlencode "query=1 - ((${errors}) / (${total})) / (1 - 0.999)" \
--data-urlencode time=1795442400
{"status":"success","data":{"resultType":"vector","result":[{"metric":{},"value":[1795442400.0,"0.05274181100791031"]}]}}
The result of 0.0527… means that about 5.3% of the error budget remains.
Summary
With Amazon CloudWatch PromQL, 30-day-wide queries are now available.
Previously the query range was limited to 7 days, but now you can calculate things like availability over the past 30 days in a single query.
If you want to calculate the availability over the past 30 days in real time on a dashboard that visualizes SLO or SLA attainment, make use of this update.
