CloudWatch (Metrics & Alarms)

Amazon CloudWatch metrics, alarms, dashboards, anomaly detectors, insight rules, and metric streams. awsQuery, awsJson1_0 and Smithy RPC v2 CBOR protocols.

fakecloud implements Amazon CloudWatch's metrics-and-alarms surface (the monitoring SigV4 service) — distinct from CloudWatch Logs, which is a separate service. CloudWatch's Smithy model advertises Smithy RPC v2 CBOR, awsJson1_0 and the legacy awsQuery protocol (XML); fakecloud accepts all three, and each caller receives a response in the protocol it used. Current aws-sdk-rust speaks RPC v2 CBOR (POST /service/GraniteServiceVersion20100801/operation/<Operation> with smithy-protocol: rpc-v2-cbor and CBOR bodies: tag-1 epoch timestamps, byte-string blobs), aws-sdk-js-v3 and botocore send X-Amz-Target: GraniteServiceVersion20100801.<Operation> with a JSON body, and older SDKs use awsQuery. CloudWatch is awsQueryCompatible, so CBOR and JSON errors carry the awsQuery error code in the x-amzn-query-error header the SDKs use to pick the modeled error. All 55 operations are implemented with persisted in-memory state.

Status: full control plane. Metrics are stored in memory and do not persist across server restarts; alarms evaluate the metric data you publish (and are re-evaluated on a timer as it ages); resources are not sampled for metrics in the background.

Supported today

  • Metrics — PutMetricData, GetMetricData, GetMetricStatistics, ListMetrics, GetMetricWidgetImage (returns a deterministic PNG blob). Custom namespaces, dimensions, and statistics round-trip.
  • Alarms — PutMetricAlarm, PutCompositeAlarm, DescribeAlarms, DescribeAlarmsForMetric, DescribeAlarmHistory, DeleteAlarms, SetAlarmState, EnableAlarmActions, DisableAlarmActions, DescribeAlarmContributors. When an alarm with ActionsEnabled changes state (by evaluation or SetAlarmState), the actions listed for the new state run: SNS topics receive the AWS alarm notification JSON (Subject ALARM: "<name>" in <Region name>), Lambda functions are invoked asynchronously with the alarm event, EC2 actions (arn:aws:automate:<region>:ec2:stop|terminate|reboot|recover and the arn:aws:swf:...:action/actions/AWS_EC2.InstanceId.<Op>/1.0 forms) act on the instance in the alarm's InstanceId dimension through EC2 (recover reboots it), Application Auto Scaling policies scale their targets, and Systems Manager OpsItem actions (arn:aws:ssm:<region>:<account>:opsitem:<severity> with an optional #CATEGORY=<category>) open an OpsItem in Systems Manager OpsCenter (source CloudWatch Alarm, title CloudWatch alarm - '<name>' is in ALARM state, the action's severity and category, the alarm's description, and the alarm and its instance as related resources in /aws/resources); while that OpsItem is unresolved the alarm opens no other. Each SNS, Lambda, EC2 and OpsItem action is recorded in DescribeAlarmHistory as an Action item (Successfully executed action <arn> / Failed to execute action <arn>); EC2 Auto Scaling group policy and Incident Manager actions are recorded as failed. A Lambda action needs the function's resource policy to grant lambda:InvokeFunction to lambda.alarms.cloudwatch.amazonaws.com, and an SNS topic in another account needs its topic policy to let CloudWatch (or the alarm's account) publish; otherwise the action is recorded as failed. PutMetricAlarm, PutCompositeAlarm and PutLogAlarm reject action ARNs that aren't a documented action form for that kind of alarm, and EC2 actions for another region. PutMetricData, and the metrics other services publish (Lambda, SNS, EventBridge, SES, Logs metric filters), evaluate the alarms on the metrics written; a timer evaluates each alarm again every minute (every period for 10- and 30-second alarms), so data ageing out and suppression periods ending take effect on their own. A state set with SetAlarmState holds until the alarm's next evaluation, or until its configuration is updated. Alarms return the computed state outputs: StateReasonData (the evaluated datapoints for a metric alarm, the triggering children for a composite alarm, or the value given to SetAlarmState), StateTransitionedTimestamp (moves only when StateValue changes, unlike StateUpdatedTimestamp), EvaluationState (EVALUATION_ERROR for a single-metric alarm whose configuration can't be evaluated, such as one with no Threshold), and on composite alarms with an ActionsSuppressor, ActionsSuppressedBy / ActionsSuppressedReason (WaitPeriod, Alarm, ExtensionPeriod). A suppressed composite alarm performs no actions; if it is still in ALARM when the suppression ends, it performs them then. A composite alarm set with SetAlarmState keeps that state until a child alarm changes state or its configuration is updated. DescribeAlarmHistory records each transition with both states' reasons and honors AlarmTypes (metric alarms only by default).
  • Dashboards — PutDashboard, GetDashboard, ListDashboards, DeleteDashboards.
  • Anomaly detectors — PutAnomalyDetector, DescribeAnomalyDetectors, DeleteAnomalyDetector (single-metric, metric-math, and metric-stat detectors).
  • Insight rules — PutInsightRule, DescribeInsightRules, EnableInsightRules, DisableInsightRules, DeleteInsightRules, GetInsightRuleReport, plus managed rules (PutManagedInsightRules, ListManagedInsightRules).
  • Metric streams — PutMetricStream, GetMetricStream, ListMetricStreams, StartMetricStreams, StopMetricStreams, DeleteMetricStream. State flips between running and stopped.
  • Alarm mute rules — PutAlarmMuteRule, GetAlarmMuteRule, ListAlarmMuteRules, DeleteAlarmMuteRule. A rule's schedule is evaluated for real: cron(Minutes Hours Day-of-month Month Day-of-week) (with *, ,, -, /, ?, L, # and JAN-DEC / SUN-SAT names) starts a window at every matching time, at(yyyy-MM-ddThh:mm) starts one, each lasting the ISO 8601 Duration (PT1M to P15D), read in the rule's Timezone (UTC by default; a local time skipped by a daylight-saving change starts no window, a repeated one starts one) and bounded by StartDate / ExpireDate. A schedule that isn't one of these forms, or names an unknown time zone, is rejected with InvalidParameterValue. Status is ACTIVE while a window is open, EXPIRED once none can open again, SCHEDULED otherwise; MuteType is ONE_TIME for at and RECURRING for cron; ListAlarmMuteRules honors AlarmName and Statuses; Tags are the rule's tags. While a rule is active, the alarms it targets (metric, composite and log alarms) keep evaluating and changing state, but the actions of every state change are held back, each recorded in the alarm history as an Action item naming the newest active rule and how many others are active (overlapping rules make one mute window). When the window ends (the schedule's window closes, or the rule expires or stops targeting the alarm), the actions configured for the alarm's current state run if that state differs from the one the window started in, and none run otherwise; deleting the rule unmutes its alarms at once, and one in ALARM runs its ALARM actions; a composite alarm's ActionsSuppressor still applies. EnableAlarmActions doesn't unmute, and a muted alarm doesn't drive Application Auto Scaling policies.
  • OTel enrichment — GetOTelEnrichment, StartOTelEnrichment, UpdateOTelEnrichment, StopOTelEnrichment, with per-namespace include / exclude metric filters (UpdateOTelEnrichment replaces both lists and requires enrichment to be running).
  • Resource metrics configurations: CreateResourceMetricsConfiguration, GetResourceMetricsConfiguration, UpdateResourceMetricsConfiguration, DeleteResourceMetricsConfiguration: one configuration per resource ARN with an optional metric selection; a duplicate create is ConflictException.
  • Tagging — TagResource, UntagResource, ListTagsForResource.

Introspection

Two IAM-bypass admin endpoints expose CloudWatch state so test assertions don't have to round-trip through the AWS SDK:

  • GET /_fakecloud/cloudwatch/alarms — every metric and composite alarm across all accounts and regions. Each entry carries accountId, region, name, type (metric or composite), state, stateReason, stateUpdatedTimestamp, actionsEnabled, and the alarmActions / okActions / insufficientDataActions lists. Metric alarms add namespace, metricName, threshold, comparisonOperator; composite alarms add alarmRule. Sorted by account, region, name.
  • GET /_fakecloud/cloudwatch/metrics — every unique metric series keyed by (account, region, namespace, metric, dimensions). Each entry carries dimensions ([{name, value}]), datapointCount, and latest ({timestamp, value, unit} or null). Sorted by account, region, namespace, metric.

All first-party SDKs ship a cloudwatch sub-client wrapping these endpoints (getAlarms(), getMetrics()). See reference/introspection for the full endpoint catalog.

Not implemented

  • No background metric sampling: alarms evaluate against the data points you publish via PutMetricData, or the state you set with SetAlarmState.
  • EC2 Auto Scaling group policy alarm actions aren't performed (fakecloud's EC2 Auto Scaling has no scaling policies), and neither are Incident Manager response plan actions (there is no Incident Manager service); both are recorded as failed actions.
  • Metric data is in-memory only and is lost on restart.
  • Metric streams persist configuration and state but do not actually fan out data points to the configured Firehose.