Skip to content

CloudWatch

CloudMock emulates Amazon CloudWatch metrics and alarms, supporting metric data ingestion, querying, alarm creation with manual state management, and tagging.

OperationStatusNotes
PutMetricDataSupportedStores metric data points
GetMetricDataSupportedRetrieves metric data with a metric query
ListMetricsSupportedReturns all metrics with optional namespace/name filter
PutMetricAlarmSupportedCreates or updates an alarm
DescribeAlarmsSupportedReturns alarms with optional name/state filter
DeleteAlarmsSupportedRemoves one or more alarms
SetAlarmStateSupportedManually sets an alarm state (OK, ALARM, INSUFFICIENT_DATA)
DescribeAlarmsForMetricSupportedReturns alarms linked to a specific metric
TagResourceSupportedAdds tags to an alarm
UntagResourceSupportedRemoves tags from an alarm
ListTagsForResourceSupportedReturns tags for an alarm
Terminal window
# Put metric data
curl -X POST "http://localhost:4566/?Action=PutMetricData&Namespace=MyApp&MetricData.member.1.MetricName=RequestCount&MetricData.member.1.Value=42&MetricData.member.1.Unit=Count"
# List metrics
curl -X POST "http://localhost:4566/?Action=ListMetrics&Namespace=MyApp"
import { CloudWatchClient, PutMetricDataCommand, PutMetricAlarmCommand } from '@aws-sdk/client-cloudwatch';
const cw = new CloudWatchClient({
endpoint: 'http://localhost:4566',
region: 'us-east-1',
credentials: { accessKeyId: 'test', secretAccessKey: 'test' },
});
await cw.send(new PutMetricDataCommand({
Namespace: 'MyService',
MetricData: [
{ MetricName: 'Errors', Value: 5, Unit: 'Count' },
{ MetricName: 'Latency', Value: 120, Unit: 'Milliseconds' },
],
}));
await cw.send(new PutMetricAlarmCommand({
AlarmName: 'HighErrorRate', MetricName: 'Errors', Namespace: 'MyService',
Statistic: 'Sum', Period: 60, EvaluationPeriods: 1,
Threshold: 10, ComparisonOperator: 'GreaterThanOrEqualToThreshold',
}));
import boto3
cw = boto3.client('cloudwatch', endpoint_url='http://localhost:4566',
aws_access_key_id='test', aws_secret_access_key='test',
region_name='us-east-1')
cw.put_metric_data(
Namespace='MyService',
MetricData=[
{'MetricName': 'Errors', 'Value': 5, 'Unit': 'Count'},
{'MetricName': 'Latency', 'Value': 120, 'Unit': 'Milliseconds'},
],
)
cw.put_metric_alarm(
AlarmName='HighErrorRate', MetricName='Errors', Namespace='MyService',
Statistic='Sum', Period=60, EvaluationPeriods=1,
Threshold=10, ComparisonOperator='GreaterThanOrEqualToThreshold',
)
# Manually trigger alarm for testing
cw.set_alarm_state(AlarmName='HighErrorRate', StateValue='ALARM', StateReason='Test')
cloudmock.yml
services:
cloudwatch:
enabled: true

No additional service-specific configuration is required.

  • Metric data is stored in memory and queryable for the duration of the process.
  • Alarm state transitions do not trigger SNS notifications or Auto Scaling actions.
  • GetMetricData supports standard statistics (Sum, Average, Min, Max, SampleCount).
  • Composite alarms are not implemented.
  • Metric math expressions are not supported.
  • Dashboards are not implemented.
CodeHTTP StatusDescription
ResourceNotFound404The specified alarm does not exist
InvalidParameterValue400An input parameter is invalid
LimitExceededFault400The request exceeds a service limit
InvalidParameterCombination400Parameters cannot be used together