CloudWatch · Operations

MetricAlarm

Declare metric alarms and their evaluation behavior.

Generic driverUniform lifecycle
Scope
Regional
Spec fields
19
Outputs
4
Lookup
Supported

Resource definition

What this resource looks like

This is the CUE shape a Praxis template uses to declare a MetricAlarm. The resource key is local to the template; metadata.name supplies its stable Praxis identity.

CUE example
resources: {
  highErrorAlarm: {
  	apiVersion: "praxis.io/alpha"
  	kind:       "MetricAlarm"
  	metadata: name: "\(_naming.prefix)-high-5xx-errors"
  	spec: {
  		region:             _naming.region
  		alarmDescription:   "ALB 5xx error rate exceeds threshold"
  		namespace:          "AWS/ApplicationELB"
  		metricName:         "HTTPCode_ELB_5XX_Count"
  		statistic:          "Sum"
  		period:             300
  		evaluationPeriods:  2
  		threshold:          50
  		comparisonOperator: "GreaterThanThreshold"
  		alarmActions: ["${resources.alertTopic.outputs.topicArn}"]
  		dimensions: LoadBalancer: "${resources.alb.outputs.loadBalancerArn}"
  		tags: #StandardTags & {purpose: "monitoring"}
  	}
  }
}

Excerpted from examples/stacks/end-to-end.cue. Open the complete example for its variables and related resources.

Complete examples in the repository

Desired state

Configuration

The spec block accepts 19 fields. 8 are required by the schema; fields with defaults can be omitted.

regionRequired

Region.

string
String
namespaceRequired

Namespace.

string
String
metricNameRequired

Metric Name.

string
String
dimensionsOptional

Dimensions.

[string]: string
Map
statisticOptional

Statistic.

"SampleCount" | "Average" | "Sum" | "Minimum" | "Maximum"
Enum
extendedStatisticOptional

Extended Statistic.

string & =~"^p[0-9]+(\\.[0-9]+)?$"
String
periodRequired

Period.

int & >0
Integer
evaluationPeriodsRequired

Evaluation Periods.

int & >=1
Integer
datapointsToAlarmOptional

Datapoints To Alarm.

int & >=1
Integer
thresholdRequired

Threshold.

number
Number
comparisonOperatorRequired

Comparison Operator.

"GreaterThanThreshold" |
Enum
treatMissingDataOptional

Treat Missing Data.

"breaching" | "notBreaching" | "ignore" | "missing" | *"missing"
EnumDefault "missing"
alarmDescriptionOptional

Alarm Description.

string
String
actionsEnabledOptional

Actions Enabled.

bool | *true
BooleanDefault true
alarmActionsOptional

Alarm Actions.

[...string]
List
okActionsOptional

Ok Actions.

[...string]
List
insufficientDataActionsOptional

Insufficient Data Actions.

[...string]
List
unitOptional

Unit.

string
String
tagsRequired

Tags.

[string]: string
Map

Observed values

Outputs

Praxis records these values after observation. A dependent resource can read one with ${resources.<name>.outputs.<field>}.

alarmArnString
alarmNameString
stateValueString
stateReasonString · optional

Read without ownership

Data-source lookup

A data block reads an existing MetricAlarm and exposes its outputs without storing lifecycle state. The generic filter surface accepts id, name, and tag; supported combinations depend on the AWS identity used by this resource.

CUE data source
data: existing: {
  kind: "MetricAlarm"
  region: "us-west-2"
  filter: {
    name: "replace-with-provider-name"
  }
}

Understand data sources and filters →

Adopt existing infrastructure

Import

Import persists Praxis state for an existing AWS resource. For this kind, supply: Provider identifier for the existing MetricAlarm. The example starts in observed mode so Praxis reports drift without correcting it.

CLI
praxis import MetricAlarm \
  --id <provider-identifier> \
  --region us-west-2 \
  --account production \
  --observe

Choose managed or observed ownership →

Canonical contract

Complete CUE schema

The field guide above is derived from this definition. The schema remains the source of truth for accepted values, defaults, validation constraints, and outputs in the current alpha revision.

Show the complete schema
schemas/aws/cloudwatch/metric_alarm.cue
package cloudwatch

#MetricAlarm: {
	apiVersion: "praxis.io/alpha"
	kind:       "MetricAlarm"

	metadata: {
		name: string & =~"^[a-zA-Z0-9][a-zA-Z0-9_\\-]{0,254}$"
		labels: [string]: string
	}

	spec: {
		region:     string
		namespace:  string
		metricName: string
		dimensions?: [string]: string
		statistic?:         "SampleCount" | "Average" | "Sum" | "Minimum" | "Maximum"
		extendedStatistic?: string & =~"^p[0-9]+(\\.[0-9]+)?$"
		period:             int & >0
		evaluationPeriods:  int & >=1
		datapointsToAlarm?: int & >=1
		threshold:          number
		comparisonOperator: "GreaterThanThreshold" |
			"GreaterThanOrEqualToThreshold" |
			"LessThanThreshold" |
					"LessThanOrEqualToThreshold"
		treatMissingData:  "breaching" | "notBreaching" | "ignore" | "missing" | *"missing"
		alarmDescription?: string
		actionsEnabled:    bool | *true
		alarmActions?: [...string]
		okActions?: [...string]
		insufficientDataActions?: [...string]
		unit?: string
		tags: [string]: string
	}

	outputs?: {
		alarmArn:     string
		alarmName:    string
		stateValue:   string
		stateReason?: string
	}
}

View this schema on GitHub →