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 withActionsEnabledchanges state (by evaluation orSetAlarmState), the actions listed for the new state run: SNS topics receive the AWS alarm notification JSON (SubjectALARM: "<name>" in <Region name>), Lambda functions are invoked asynchronously with the alarm event, EC2 actions (arn:aws:automate:<region>:ec2:stop|terminate|reboot|recoverand thearn:aws:swf:...:action/actions/AWS_EC2.InstanceId.<Op>/1.0forms) act on the instance in the alarm'sInstanceIddimension through EC2 (recoverreboots 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 (sourceCloudWatch Alarm, titleCloudWatch 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 inDescribeAlarmHistoryas anActionitem (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 grantlambda:InvokeFunctiontolambda.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,PutCompositeAlarmandPutLogAlarmreject 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 withSetAlarmStateholds 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 toSetAlarmState),StateTransitionedTimestamp(moves only whenStateValuechanges, unlikeStateUpdatedTimestamp),EvaluationState(EVALUATION_ERRORfor a single-metric alarm whose configuration can't be evaluated, such as one with noThreshold), and on composite alarms with anActionsSuppressor,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 withSetAlarmStatekeeps that state until a child alarm changes state or its configuration is updated.DescribeAlarmHistoryrecords each transition with both states' reasons and honorsAlarmTypes(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 betweenrunningandstopped. - 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,#andJAN-DEC/SUN-SATnames) starts a window at every matching time,at(yyyy-MM-ddThh:mm)starts one, each lasting the ISO 8601Duration(PT1MtoP15D), read in the rule'sTimezone(UTC by default; a local time skipped by a daylight-saving change starts no window, a repeated one starts one) and bounded byStartDate/ExpireDate. A schedule that isn't one of these forms, or names an unknown time zone, is rejected withInvalidParameterValue.StatusisACTIVEwhile a window is open,EXPIREDonce none can open again,SCHEDULEDotherwise;MuteTypeisONE_TIMEforatandRECURRINGforcron;ListAlarmMuteRuleshonorsAlarmNameandStatuses;Tagsare 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 anActionitem 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'sActionsSuppressorstill applies.EnableAlarmActionsdoesn'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 (UpdateOTelEnrichmentreplaces 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 isConflictException. - 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 carriesaccountId,region,name,type(metricorcomposite),state,stateReason,stateUpdatedTimestamp,actionsEnabled, and thealarmActions/okActions/insufficientDataActionslists. Metric alarms addnamespace,metricName,threshold,comparisonOperator; composite alarms addalarmRule. Sorted by account, region, name.GET /_fakecloud/cloudwatch/metrics— every unique metric series keyed by (account, region, namespace, metric, dimensions). Each entry carriesdimensions([{name, value}]),datapointCount, andlatest({timestamp, value, unit}ornull). 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 withSetAlarmState. - 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.