setAlarmState method

Future<void> setAlarmState({
  1. required String alarmName,
  2. required String stateReason,
  3. required StateValue stateValue,
  4. String? stateReasonData,
})

Temporarily sets the state of an alarm for testing purposes. When the updated state differs from the previous value, the action configured for the appropriate state is invoked. For example, if your alarm is configured to send an Amazon SNS message when an alarm is triggered, temporarily changing the alarm state to ALARM sends an SNS message.

Metric alarms returns to their actual state quickly, often within seconds. Because the metric alarm state change happens quickly, it is typically only visible in the alarm's History tab in the Amazon CloudWatch console or through DescribeAlarmHistory.

If you use SetAlarmState on a composite alarm, the composite alarm is not guaranteed to return to its actual state. It returns to its actual state only once any of its children alarms change state. It is also reevaluated if you update its configuration.

If an alarm triggers EC2 Auto Scaling policies or application Auto Scaling policies, you must include information in the StateReasonData parameter to enable the policy to take the correct action.

May throw ResourceNotFound. May throw InvalidFormatFault.

Parameter alarmName : The name of the alarm.

Parameter stateReason : The reason that this alarm is set to this specific state, in text format.

Parameter stateValue : The value of the state.

Parameter stateReasonData : The reason that this alarm is set to this specific state, in JSON format.

For SNS or EC2 alarm actions, this is just informational. But for EC2 Auto Scaling or application Auto Scaling alarm actions, the Auto Scaling policy uses the information in this field to take the correct action.

Implementation

Future<void> setAlarmState({
  required String alarmName,
  required String stateReason,
  required StateValue stateValue,
  String? stateReasonData,
}) async {
  ArgumentError.checkNotNull(alarmName, 'alarmName');
  _s.validateStringLength(
    'alarmName',
    alarmName,
    1,
    255,
    isRequired: true,
  );
  ArgumentError.checkNotNull(stateReason, 'stateReason');
  _s.validateStringLength(
    'stateReason',
    stateReason,
    0,
    1023,
    isRequired: true,
  );
  ArgumentError.checkNotNull(stateValue, 'stateValue');
  _s.validateStringLength(
    'stateReasonData',
    stateReasonData,
    0,
    4000,
  );
  final $request = <String, dynamic>{};
  $request['AlarmName'] = alarmName;
  $request['StateReason'] = stateReason;
  $request['StateValue'] = stateValue.toValue();
  stateReasonData?.also((arg) => $request['StateReasonData'] = arg);
  await _protocol.send(
    $request,
    action: 'SetAlarmState',
    version: '2010-08-01',
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    shape: shapes['SetAlarmStateInput'],
    shapes: shapes,
  );
}