# AlarmRule

Class with static functions to build AlarmRule for Composite Alarms.

- Source: [`aws-cloudwatch/lib/alarm-rule.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-cloudwatch/lib/alarm-rule.ts#L157)
- Type last changed: v2.265.0 · 13 Aug 2026

## Example

TypeScript:

```ts
declare const alarm1: cloudwatch.Alarm;
declare const alarm2: cloudwatch.Alarm;
declare const onAlarmAction: cloudwatch.IAlarmAction;
declare const onOkAction: cloudwatch.IAlarmAction;
declare const actionsSuppressor: cloudwatch.Alarm;

const alarmRule = cloudwatch.AlarmRule.anyOf(alarm1, alarm2);

const myCompositeAlarm = new cloudwatch.CompositeAlarm(this, 'MyAwesomeCompositeAlarm', {
  alarmRule,
  actionsSuppressor,
});
myCompositeAlarm.addAlarmAction(onAlarmAction);
myCompositeAlarm.addOkAction(onOkAction);
```

Python:

```python
# alarm1: cloudwatch.Alarm
# alarm2: cloudwatch.Alarm
# on_alarm_action: cloudwatch.IAlarmAction
# on_ok_action: cloudwatch.IAlarmAction
# actions_suppressor: cloudwatch.Alarm

alarm_rule = cloudwatch.AlarmRule.any_of(alarm1, alarm2)

my_composite_alarm = cloudwatch.CompositeAlarm(self, "MyAwesomeCompositeAlarm",
    alarm_rule=alarm_rule,
    actions_suppressor=actions_suppressor
)
my_composite_alarm.add_alarm_action(on_alarm_action)
my_composite_alarm.add_ok_action(on_ok_action)
```

Java:

```java
Alarm alarm1;
Alarm alarm2;
IAlarmAction onAlarmAction;
IAlarmAction onOkAction;
Alarm actionsSuppressor;

IAlarmRule alarmRule = AlarmRule.anyOf(alarm1, alarm2);

CompositeAlarm myCompositeAlarm = CompositeAlarm.Builder.create(this, "MyAwesomeCompositeAlarm")
        .alarmRule(alarmRule)
        .actionsSuppressor(actionsSuppressor)
        .build();
myCompositeAlarm.addAlarmAction(onAlarmAction);
myCompositeAlarm.addOkAction(onOkAction);
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
Alarm alarm1;
Alarm alarm2;
IAlarmAction onAlarmAction;
IAlarmAction onOkAction;
Alarm actionsSuppressor;

var alarmRule = AlarmRule.AnyOf(alarm1, alarm2);

var myCompositeAlarm = new CompositeAlarm(this, "MyAwesomeCompositeAlarm", new CompositeAlarmProps {
    AlarmRule = alarmRule,
    ActionsSuppressor = actionsSuppressor
});
myCompositeAlarm.AddAlarmAction(onAlarmAction);
myCompositeAlarm.AddOkAction(onOkAction);
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var alarm1 Alarm
var alarm2 Alarm
var onAlarmAction IAlarmAction
var onOkAction IAlarmAction
var actionsSuppressor Alarm

alarmRule := cloudwatch.AlarmRule_AnyOf(alarm1, alarm2)

myCompositeAlarm := cloudwatch.NewCompositeAlarm(this, jsii.String("MyAwesomeCompositeAlarm"), &CompositeAlarmProps{
	AlarmRule: AlarmRule,
	ActionsSuppressor: ActionsSuppressor,
})
myCompositeAlarm.AddAlarmAction(onAlarmAction)
myCompositeAlarm.AddOkAction(onOkAction)
```

## Initializer

TypeScript:

```ts
new AlarmRule()
```

Python:

```python
AlarmRule()
```

Java:

```java
new AlarmRule()
```

C# / .NET:

```csharp
new AlarmRule()
```

Golang:

```go
NewAlarmRule()
```

## Methods

- `allOf(...operands: IAlarmRule[]): IAlarmRule` (static) — function to join all provided AlarmRules with AND operator.

  **Parameters**

  - `operands` — IAlarmRules to be joined with AND operator.

- `anyOf(...operands: IAlarmRule[]): IAlarmRule` (static) — function to join all provided AlarmRules with OR operator.

  **Parameters**

  - `operands` — IAlarmRules to be joined with OR operator.

- `atLeast(alarmState: AlarmState, options: AtLeastOptions): IAlarmRule` (static) — function to create an AT_LEAST expression for the given alarm state.

  **Parameters**

  - `alarmState` — the alarm state to evaluate against.
  - `options` — operands and threshold for the AT_LEAST expression.

- `atLeastNot(alarmState: AlarmState, options: AtLeastOptions): IAlarmRule` (static) — function to create an AT_LEAST expression for the negated alarm state.

  **Parameters**

  - `alarmState` — the alarm state to negate and evaluate against.
  - `options` — operands and threshold for the AT_LEAST expression.

- `fromAlarm(alarm: IAlarmRef, alarmState: AlarmState): IAlarmRule` (static) — function to build Rule Expression for given IAlarm and AlarmState.

  **Parameters**

  - `alarm` — IAlarm to be used in Rule Expression.
  - `alarmState` — AlarmState to be used in Rule Expression.

- `fromBoolean(value: boolean): IAlarmRule` (static) — function to build TRUE/FALSE intent for Rule Expression.

  **Parameters**

  - `value` — boolean value to be used in rule expression.

- `fromString(alarmRule: string): IAlarmRule` (static) — function to build Rule Expression for given Alarm Rule string.

  **Parameters**

  - `alarmRule` — string to be used in Rule Expression.

- `not(operand: IAlarmRule): IAlarmRule` (static) — function to wrap provided AlarmRule in NOT operator.

  **Parameters**

  - `operand` — IAlarmRule to be wrapped in NOT operator.
